Skip to content

Commit f50b59e

Browse files
committed
AdnlLiteClient - WIP
1 parent 7ee8b97 commit f50b59e

File tree

5 files changed

+20
-89
lines changed

5 files changed

+20
-89
lines changed

adnl/src/main/java/org/ton/java/adnl/AdnlTcpTransport.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.net.*;
55
import java.nio.ByteBuffer;
66
import java.nio.ByteOrder;
7+
import java.nio.charset.StandardCharsets;
78
import java.security.MessageDigest;
89
import java.security.SecureRandom;
910
import java.util.*;
@@ -150,7 +151,7 @@ private byte[] calculateKeyId(byte[] publicKey) throws Exception {
150151
// Calculate TL constructor ID for pub.ed25519 schema
151152
String tlSchema = "pub.ed25519 key:int256 = PublicKey";
152153
CRC32 crc32 = new CRC32();
153-
crc32.update(tlSchema.getBytes("UTF-8"));
154+
crc32.update(tlSchema.getBytes(StandardCharsets.UTF_8));
154155
long constructorId = crc32.getValue();
155156

156157
// Build TL-serialized structure: constructor_id + key
@@ -176,7 +177,7 @@ private void waitForHandshakeConfirmation() throws Exception {
176177
long timeout = System.currentTimeMillis() + 10000; // 10 second timeout
177178

178179
while (System.currentTimeMillis() < timeout && !connected) {
179-
Thread.sleep(100);
180+
Utils.sleepMs(100);
180181
// Check if listener thread is still running
181182
if (listenerThread != null && !listenerThread.isAlive()) {
182183
throw new Exception("Packet listener thread died during handshake");
@@ -211,9 +212,6 @@ private void listenForPackets() {
211212
if (packetSizeLong > 16 * 1024 * 1024) { // 16MB limit
212213
throw new IOException("Packet too large: " + packetSizeLong);
213214
}
214-
if (packetSizeLong < 0) { // Negative size is invalid
215-
throw new IOException("Invalid packet size: " + packetSizeLong);
216-
}
217215

218216
int packetSize = (int) packetSizeLong;
219217

adnl/src/main/java/org/ton/java/adnl/CryptoUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public class CryptoUtils {
2727
public static byte[] getSharedKey(byte[] privateKey, byte[] publicKey) {
2828
TweetNaclFast.Box box = new TweetNaclFast.Box(publicKey, privateKey);
2929
byte[] zero = new byte[24];
30-
byte[] sharedKey = box.before();
31-
return sharedKey;
30+
return box.before();
3231
}
3332

3433
/**

adnl/src/main/java/org/ton/java/adnl/LiteClientConnectionPool.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.concurrent.atomic.AtomicInteger;
66
import java.util.function.Function;
77
import lombok.extern.slf4j.Slf4j;
8+
import org.apache.commons.lang3.NotImplementedException;
89
import org.ton.java.adnl.globalconfig.LiteServers;
910
import org.ton.java.adnl.globalconfig.TonGlobalConfig;
1011
import org.ton.ton4j.utils.Utils;
@@ -23,8 +24,9 @@ public class LiteClientConnectionPool {
2324

2425
/** Create connection pool */
2526
public LiteClientConnectionPool() {
26-
this.healthChecker = Executors.newSingleThreadScheduledExecutor();
27-
startHealthChecker();
27+
throw new NotImplementedException();
28+
// this.healthChecker = Executors.newSingleThreadScheduledExecutor();
29+
// startHealthChecker();
2830
}
2931

3032
/**

adnl/src/main/java/org/ton/java/adnl/Server.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

adnl/src/test/java/org/ton/java/adnl/AdnlLiteClientTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,17 @@ void testGetTransactionsByLtHash() throws Exception {
722722
}
723723
}
724724

725+
@Test
726+
void testLookupBlockMode1() throws Exception { // by LT
727+
log.info("Testing lookupBlock query");
728+
assertTrue(client.isConnected(), "Client should be connected");
729+
730+
MasterchainInfo masterchainInfo = client.getMasterchainInfo();
731+
732+
BlockHeader blockHeader = client.lookupBlock(masterchainInfo.getLast().getBlockId(), 1, 0, 0);
733+
log.info("blockHeader {}", blockHeader);
734+
}
735+
725736
@Test
726737
void testLookupBlockMode2() throws Exception { // by LT
727738
log.info("Testing lookupBlock query");
@@ -1132,10 +1143,9 @@ void testValidatorStatsMode4() throws Exception {
11321143

11331144
MasterchainInfo masterchainInfo = client.getMasterchainInfo();
11341145
ValidatorStats validatorStats =
1135-
client.getValidatorStats(masterchainInfo.getLast(), 4, 10, null, 0);
1146+
client.getValidatorStats(masterchainInfo.getLast(), 4, 10, new byte[32], 0);
11361147

11371148
log.info("validatorStats {}", validatorStats);
1138-
// todo
11391149
}
11401150

11411151
@Test

0 commit comments

Comments
 (0)