Skip to content

Commit

Permalink
SSU2: Peer Test fixes part 6
Browse files Browse the repository at this point in the history
Change size/ip/port fields to match changes in proposal 159
  • Loading branch information
zzzi2p committed Apr 27, 2022
1 parent 71a58cb commit 008943f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
10 changes: 10 additions & 0 deletions history.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2022-04-27 zzz
* SSU2: Peer test updates and fixes

2022-04-24 zzz
* SSU: Publish empty IPv6 address when missing introducers
* SSU2: Finish peer test implementation

2022-04-17 zzz
* More soft restart fixes

2022-04-14 zzz
* Startup: Don't set our RI loaded from disk if too old

Expand Down
2 changes: 1 addition & 1 deletion router/java/src/net/i2p/router/RouterVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Git";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 14;
public final static long BUILD = 15;

/** for example "-test" */
public final static String EXTRA = "";
Expand Down
26 changes: 15 additions & 11 deletions router/java/src/net/i2p/router/transport/udp/PeerTestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ private void sendTestToCharlie() {
data[1] = 2; // version
DataHelper.toLong(data, 2, 4, nonce);
DataHelper.toLong(data, 6, 4, _context.clock().now() / 1000);
data[10] = (byte) iplen;
System.arraycopy(aliceIP, 0, data, 11, iplen);
DataHelper.toLong(data, 11 + iplen, 2, alicePort);
data[10] = (byte) (iplen + 2);
DataHelper.toLong(data, 11, 2, alicePort);
System.arraycopy(aliceIP, 0, data, 13, iplen);
packet = _packetBuilder2.buildPeerTestFromAlice(test.getCharlieIP(), test.getCharliePort(),
test.getCharlieIntroKey(),
sendId, rcvId, data);
Expand Down Expand Up @@ -842,20 +842,24 @@ public void receiveTest(RemoteHostId from, PeerState2 fromPeer, int msg, int sta
long nonce = DataHelper.fromLong(data, 2, 4);
long time = DataHelper.fromLong(data, 6, 4) * 1000;
int iplen = data[10] & 0xff;
if (iplen != 0 && iplen != 4 && iplen != 16) {
if (iplen != 0 && iplen != 6 && iplen != 18) {
if (_log.shouldLog(Log.WARN))
_log.warn("Bad IP length " + iplen);
return;
}
boolean isIPv6 = iplen == 16;
boolean isIPv6 = iplen == 18;
int testPort;
byte[] testIP;
if (iplen != 0) {
testIP = new byte[iplen];
System.arraycopy(data, 11, testIP, 0, iplen);
testPort = (int) DataHelper.fromLong(data, 11, 2);
testIP = new byte[iplen - 2];
System.arraycopy(data, 13, testIP, 0, iplen - 2);
} else {
testPort = 0;
testIP = null;
if (status == 0)
status = 999;
}
int testPort = (int) DataHelper.fromLong(data, 11 + iplen, 2);
Long lNonce = Long.valueOf(nonce);
PeerTestState state;
if (msg == 4 || msg == 5 || msg == 7)
Expand Down Expand Up @@ -1285,9 +1289,9 @@ public void receiveTest(RemoteHostId from, PeerState2 fromPeer, int msg, int sta
data[1] = 2; // version
DataHelper.toLong(data, 2, 4, nonce);
DataHelper.toLong(data, 6, 4, now / 1000);
data[10] = (byte) iplen;
System.arraycopy(aliceIP, 0, data, 11, iplen);
DataHelper.toLong(data, 11 + iplen, 2, alicePort);
data[10] = (byte) (iplen + 2);
DataHelper.toLong(data, 11, 2, alicePort);
System.arraycopy(aliceIP, 0, data, 13, iplen);
if (_log.shouldDebug())
_log.debug("Send msg 7 to alice on " + state);
UDPPacket packet = _packetBuilder2.buildPeerTestToAlice(addr, alicePort,
Expand Down
11 changes: 6 additions & 5 deletions router/java/src/net/i2p/router/transport/udp/SSU2Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static byte[] hkdf(I2PAppContext ctx, byte[] key, String info) {
public static byte[] createPeerTestData(I2PAppContext ctx, Hash h, Hash h2,
PeerTestState.Role role, long nonce, byte[] ip, int port,
SigningPrivateKey spk) {
int datalen = 13 + ip.length;
int datalen = 13 + (ip != null ? ip.length : 0);
byte[] data = new byte[datalen + spk.getType().getSigLen()];
if (role == PeerTestState.Role.BOB)
throw new IllegalArgumentException();
Expand All @@ -188,10 +188,11 @@ public static byte[] createPeerTestData(I2PAppContext ctx, Hash h, Hash h2,
DataHelper.toLong(data, 2, 4, nonce);
DataHelper.toLong(data, 6, 4, ctx.clock().now() / 1000);
int iplen = (ip != null) ? ip.length : 0;
data[10] = (byte) iplen;
if (ip != null)
System.arraycopy(ip, 0, data, 11, iplen);
DataHelper.toLong(data, 11 + iplen, 2, port);
data[10] = (byte) (ip != null ? iplen + 2 : 0);
if (ip != null) {
DataHelper.toLong(data, 11, 2, port);
System.arraycopy(ip, 0, data, 13, iplen);
}
Signature sig = sign(ctx, PEER_TEST_PROLOGUE, h, h2, data, datalen, spk);
if (sig == null)
return null;
Expand Down

0 comments on commit 008943f

Please sign in to comment.