SSU2: Post-termination handler part 4 WIP

Save destroy reason in PeerState2
Add PeerState2 methods to get data for new handler
Log when token received
This commit is contained in:
zzz
2022-12-06 12:18:56 -05:00
parent 2451ea31bb
commit ad18c98330
2 changed files with 17 additions and 1 deletions
@@ -359,6 +359,7 @@ class PacketBuilder2 {
public UDPPacket buildSessionDestroyPacket(int reason, SSU2Sender peer) {
if (_log.shouldDebug())
_log.debug("Sending termination " + reason + " to : " + peer);
peer.setDestroyReason(reason);
List<Block> blocks = new ArrayList<Block>(2);
if (peer.isIPv6() || !_transport.isSnatted()) {
// update token
@@ -67,6 +67,7 @@ public class PeerState2 extends PeerState implements SSU2Payload.PayloadCallback
private long _sentMessagesLastExpired;
private byte[] _ourIP;
private int _ourPort;
private int _destroyReason;
// Session Confirmed retransmit
private byte[][] _sessConfForReTX;
@@ -328,7 +329,7 @@ public class PeerState2 extends PeerState implements SSU2Payload.PayloadCallback
/**
* @since 0.9.57
*/
public void setDestroyReason(int reason) { /* todo */ }
public void setDestroyReason(int reason) { _destroyReason = reason; }
/// end SSU2Sender interface ///
@@ -336,6 +337,18 @@ public class PeerState2 extends PeerState implements SSU2Payload.PayloadCallback
byte[] getRcvHeaderEncryptKey1() { return _rcvHeaderEncryptKey1; }
byte[] getRcvHeaderEncryptKey2() { return _rcvHeaderEncryptKey2; }
/**
* @return 0 (REASON_UNSPEC) if unset
* @since 0.9.57 for PeerStateDestroyed
*/
int getDestroyReason() { return _destroyReason; }
/**
* @since 0.9.57 for PeerStateDestroyed
*/
CipherState getRcvCipher() { return _rcvCha; }
void setOurAddress(byte[] ip, int port) {
_ourIP = ip; _ourPort = port;
}
@@ -663,6 +676,8 @@ public class PeerState2 extends PeerState implements SSU2Payload.PayloadCallback
}
public void gotToken(long token, long expires) {
if (_log.shouldInfo())
_log.info("Got TOKEN block: " + token + " expires " + DataHelper.formatTime(expires) + " on " + this);
_transport.getEstablisher().addOutboundToken(_remoteHostId, token, expires);
}