Skip to content

Commit 4858771

Browse files
committed
Hashing and dependency updates
1 parent 89e1e85 commit 4858771

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

convex-core/src/main/java/convex/core/crypto/Hashing.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.bouncycastle.jcajce.provider.digest.Keccak;
88

9+
import convex.core.data.ABlobLike;
910
import convex.core.data.Hash;
1011
import convex.core.exceptions.Panic;
1112

@@ -152,5 +153,13 @@ protected MessageDigest initialValue() {
152153
return new Keccak.Digest256();
153154
}
154155
};
156+
157+
public static Hash sha256(ABlobLike<?> data) {
158+
return data.toBlob().computeHash(getSHA256Digest());
159+
}
160+
161+
public static Hash sha3(ABlobLike<?> data) {
162+
return data.toBlob().getContentHash();
163+
}
155164

156165
}

convex-core/src/main/java/convex/core/lang/RT.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,31 @@ public static ACell getIn(ACell coll, Object... keys) {
14031403
}
14041404
return result;
14051405
}
1406+
1407+
public static ACell assocIn(ACell a, ACell value, Object... keys) {
1408+
int n=keys.length;
1409+
ADataStructure<?>[] ass=new ADataStructure[n];
1410+
ACell[] ks=new ACell[n];
1411+
ACell data=a;
1412+
for (int i = 0; i < n; i++) {
1413+
ADataStructure<?> struct = RT.ensureAssociative(data); // nil-> empty map
1414+
if (struct == null) throw new IllegalArgumentException("Not a data structure at depth: "+i);
1415+
ass[i]=struct;
1416+
ACell k=RT.cvm(keys[i]);
1417+
ks[i]=k;
1418+
data=struct.get(k);
1419+
}
1420+
1421+
for (int i = n-1; i >=0; i--) {
1422+
ADataStructure<?> struct=ass[i];
1423+
ACell k=ks[i];
1424+
value=RT.assoc(struct, k, value);
1425+
if (value==null) {
1426+
throw new IllegalArgumentException("Invalid structure for assocIn at depth "+i);
1427+
}
1428+
}
1429+
return value;
1430+
}
14061431

14071432
/**
14081433
* Gets an element from a data structure using the given key. Returns the
@@ -1922,4 +1947,6 @@ public static long[] toLongArray(AVector<?> v) {
19221947
return result;
19231948
}
19241949

1950+
1951+
19251952
}

convex-peer/src/main/java/convex/net/impl/netty/NettyConnection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import io.netty.channel.ChannelFuture;
2020
import io.netty.channel.ChannelInitializer;
2121
import io.netty.channel.ChannelOption;
22-
import io.netty.channel.EventLoopGroup;
23-
import io.netty.channel.nio.NioEventLoopGroup;
22+
import io.netty.channel.*;
23+
import io.netty.channel.nio.NioIoHandler;
2424
import io.netty.channel.socket.SocketChannel;
2525
import io.netty.channel.socket.nio.NioSocketChannel;
2626

@@ -51,7 +51,7 @@ protected static EventLoopGroup getEventLoopGroup() {
5151
synchronized (NettyConnection.class) {
5252
if (workerGroup != null)
5353
return workerGroup;
54-
workerGroup = new NioEventLoopGroup();
54+
workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
5555

5656
Shutdown.addHook(Shutdown.CONNECTION, () -> {
5757
if (workerGroup != null) {

convex-peer/src/main/java/convex/net/impl/netty/NettyServer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import io.netty.channel.ChannelInitializer;
2121
import io.netty.channel.ChannelOption;
2222
import io.netty.channel.EventLoopGroup;
23-
import io.netty.channel.nio.NioEventLoopGroup;
23+
import io.netty.channel.MultiThreadIoEventLoopGroup;
24+
import io.netty.channel.nio.NioIoHandler;
2425
import io.netty.channel.socket.SocketChannel;
2526
import io.netty.channel.socket.nio.NioServerSocketChannel;
2627

@@ -32,7 +33,7 @@ public class NettyServer extends AServer {
3233

3334
protected synchronized static EventLoopGroup getEventLoopGroup() {
3435
if (bossGroup!=null) return bossGroup;
35-
bossGroup=new NioEventLoopGroup();
36+
bossGroup=new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
3637
Shutdown.addHook(Shutdown.SERVER,()->{
3738
if (bossGroup!=null) {
3839
bossGroup.shutdownGracefully();

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3232
<logback.version>1.5.12</logback.version>
3333
<jmh.version>1.37</jmh.version>
34-
<junit.version>5.12.2</junit.version>
34+
<junit.version>5.13.0</junit.version>
3535
<slf4j.version>2.0.16</slf4j.version>
3636
<hc.version>5.4.1</hc.version>
3737
<convex.version>${project.version}</convex.version>

0 commit comments

Comments
 (0)