diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java index 8b022d9fc..2ed7885b3 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/bytestreams/socks5/packet/Bytestream.java @@ -455,4 +455,26 @@ public class Bytestream extends IQ { return mode; } } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + + if (!(other instanceof Bytestream)) { + return false; + } + + Bytestream o = (Bytestream) other; + + return o.getMode() == getMode() && + o.getSessionID().equals(getSessionID()) && + o.getStreamHosts().equals(getStreamHosts()); + } + + @Override + public int hashCode() { + return 31 * getStreamHosts().hashCode() + 29 * getSessionID().hashCode() + 23 * getMode().hashCode(); + } } diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransport.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransport.java index 19bd3c307..0698a94ad 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransport.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/transport/jingle_s5b/JingleS5BTransport.java @@ -102,9 +102,9 @@ public class JingleS5BTransport extends JingleTransport> ourCandidates, JingleS5BTransport other) { - this.sid = other.sid; + this.sid = other.getSid(); this.mode = other.mode; - this.ourDstAddr = Socks5Utils.createDigest(other.sid, responder, initiator); + this.ourDstAddr = Socks5Utils.createDigest(sid, responder, initiator); Socks5Proxy.getSocks5Proxy().addTransfer(ourDstAddr); this.theirDstAddr = other.theirDstAddr; @@ -232,6 +232,7 @@ public class JingleS5BTransport extends JingleTransport> c1 = new ArrayList<>(); + JingleS5BTransportCandidate c11 = new JingleS5BTransportCandidate("1234", new Bytestream.StreamHost(JidCreate.from("p.b.c"), "p.b.c", 9999), 100, JingleS5BTransportCandidateElement.Type.proxy); + c1.add(c11); + + List> c2 = new ArrayList<>(); + JingleS5BTransportCandidate c21 = new JingleS5BTransportCandidate("1337", new Bytestream.StreamHost(JidCreate.from("p.a.b"), "p.a.b", 1000), 101, JingleS5BTransportCandidateElement.Type.proxy); + JingleS5BTransportCandidate c22 = new JingleS5BTransportCandidate("1009", new Bytestream.StreamHost(JidCreate.from("p.a.b"), "p.a.b", 2000), 10, JingleS5BTransportCandidateElement.Type.proxy); + c2.add(c21); + c2.add(c22); + + + JingleS5BTransport t1 = new JingleS5BTransport(initiator, responder, "tSes", Bytestream.Mode.tcp, c1); + + assertEquals("tSes", t1.getSid()); + assertEquals(Bytestream.Mode.tcp, t1.getMode()); + + assertEquals(Socks5Utils.createDigest("tSes", initiator, responder), t1.getOurDstAddr()); + assertNull(t1.getTheirDstAddr()); + + assertEquals(1, t1.getOurCandidates().size()); + assertEquals(c11, t1.getOurCandidates().get(0)); + assertEquals(0, t1.getTheirCandidates().size()); + + + JingleS5BTransport t1parsed = new JingleS5BTransportAdapter().transportFromElement(t1.getElement()); + + assertEquals(t1.getOurDstAddr(), t1parsed.getTheirDstAddr()); + assertNull(t1parsed.getOurDstAddr()); + assertEquals(0, t1parsed.getOurCandidates().size()); + assertEquals(t1.getSid(), t1parsed.getSid()); + assertEquals(t1.getMode(), t1parsed.getMode()); + assertEquals(t1.getOurCandidates().size(), t1parsed.getTheirCandidates().size()); + + JingleS5BTransport t2 = new JingleS5BTransport(initiator, responder, c2, t1parsed); + + assertEquals("tSes", t2.getSid()); + assertEquals(Bytestream.Mode.tcp, t2.getMode()); + + assertEquals(Socks5Utils.createDigest("tSes", responder, initiator), t2.getOurDstAddr()); + assertEquals(t1.getOurDstAddr(), t2.getTheirDstAddr()); + + assertEquals(2, t2.getOurCandidates().size()); + assertEquals(c2, t2.getOurCandidates()); + assertEquals(t1.getOurCandidates().size(), t2.getTheirCandidates().size()); + } + @Test(expected = IllegalArgumentException.class) public void typeFromIllegalStringTest() { JingleS5BTransportCandidateElement.Type.fromString("illegal-type");