Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 20 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 27, 2012
@sanity commit 4be4e8d
Commits on May 02, 2012
@sanity merge ee7be35
Showing with 213 additions and 240 deletions.
  1. +55 −0 src/main/java/tahrir/RemoteNodeAddress.java
  2. +2 −2 src/main/java/tahrir/TrConfig.java
  3. +15 −73 src/main/java/tahrir/TrNode.java
  4. +1 −1  src/main/java/tahrir/io/net/{TrRemoteAddress.java → PhysicalNetworkLocation.java}
  5. +12 −12 src/main/java/tahrir/io/net/TrNet.java
  6. +5 −5 src/main/java/tahrir/io/net/TrNetworkInterface.java
  7. +24 −31 src/main/java/tahrir/{peerManager → io/net}/TrPeerManager.java
  8. +3 −3 src/main/java/tahrir/io/net/TrRemoteConnection.java
  9. +10 −10 src/main/java/tahrir/io/net/TrSessionImpl.java
  10. +4 −4 src/main/java/tahrir/io/net/sessions/AssimilateSession.java
  11. +28 −30 src/main/java/tahrir/io/net/sessions/AssimilateSessionImpl.java
  12. +19 −34 src/main/java/tahrir/io/net/udpV1/UdpNetworkInterface.java
  13. +5 −5 src/main/java/tahrir/io/net/udpV1/{UdpRemoteAddress.java → UdpNetworkLocation.java}
  14. +3 −3 src/main/java/tahrir/io/net/udpV1/UdpRemoteConnection.java
  15. +2 −2 src/main/java/tahrir/io/serialization/TrSerializer.java
  16. +9 −9 .../tahrir/io/serialization/serializers/{TrRemoteAddressSerializer.java → NetworkLocationSerializer.java}
  17. +4 −4 src/test/java/tahrir/io/net/TrNetTest.java
  18. +2 −3 src/test/java/tahrir/io/net/sessions/AssimilateTest.java
  19. +6 −5 src/test/java/tahrir/io/net/udpV1/UdpNetworkInterfaceTest.java
  20. +4 −4 src/test/java/tahrir/io/serialization/SerializationTest.java
View
55 src/main/java/tahrir/RemoteNodeAddress.java
@@ -0,0 +1,55 @@
+package tahrir;
+
+import java.security.interfaces.RSAPublicKey;
+
+import tahrir.io.net.PhysicalNetworkLocation;
+
+public class RemoteNodeAddress {
+ public PhysicalNetworkLocation location;
+ public RSAPublicKey publicKey;
+
+ public RemoteNodeAddress() {
+
+ }
+
+ public RemoteNodeAddress(final PhysicalNetworkLocation location,final RSAPublicKey publicKey) {
+ this.location = location;
+ this.publicKey = publicKey;
+ }
+
+
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((location == null) ? 0 : location.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof RemoteNodeAddress))
+ return false;
+ final RemoteNodeAddress other = (RemoteNodeAddress) obj;
+ if (location == null) {
+ if (other.location != null)
+ return false;
+ } else if (!location.equals(other.location))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("RemoteNodeAddress [address=");
+ builder.append(location);
+ builder.append("]");
+ return builder.toString();
+ }
+}
View
4 src/main/java/tahrir/TrConfig.java
@@ -1,8 +1,8 @@
package tahrir;
+import tahrir.io.net.*;
+import tahrir.io.net.TrPeerManager.Capabilities;
import tahrir.io.net.udpV1.UdpNetworkInterface.UNIConfig;
-import tahrir.peerManager.*;
-import tahrir.peerManager.TrPeerManager.Capabilities;
public class TrConfig {
public String privateNodeId = "myprivnodeid.dat";
View
88 src/main/java/tahrir/TrNode.java
@@ -13,7 +13,6 @@
import tahrir.io.net.*;
import tahrir.io.net.sessions.*;
import tahrir.io.net.udpV1.*;
-import tahrir.peerManager.TrPeerManager;
import tahrir.tools.*;
import tahrir.tools.Persistence.Modified;
import tahrir.tools.Persistence.ModifyBlock;
@@ -45,16 +44,16 @@ public TrNode(final File rootDirectory, final TrConfig config)
pubNodeIdFile = new File(rootDirectory, config.publicNodeId);
if (!privNodeIdFile.exists()) {
logger.info("Generating new Node ID");
- final Tuple2<PrivateNodeId, PublicNodeId> kp = PrivateNodeId.generate();
+ final Tuple2<PrivateNodeId, RemoteNodeAddress> kp = PrivateNodeId.generate();
Persistence.save(privNodeIdFile, kp.a);
Persistence.save(pubNodeIdFile, kp.b);
}
if (config.localHostName != null) {
- modifyPublicNodeId(new ModifyBlock<TrNode.PublicNodeId>() {
+ modifyPublicNodeId(new ModifyBlock<RemoteNodeAddress>() {
- public void run(final PublicNodeId publicNodeId, final Modified modified) {
+ public void run(final RemoteNodeAddress remoteNodeAddress, final Modified modified) {
try {
- publicNodeId.address = new UdpRemoteAddress(InetAddress.getByName(config.localHostName),
+ remoteNodeAddress.location = new UdpNetworkLocation(InetAddress.getByName(config.localHostName),
config.udp.listenPort);
} catch (final UnknownHostException e) {
logger.error("Failed to set local node address", e);
@@ -68,7 +67,7 @@ public void run(final PublicNodeId publicNodeId, final Modified modified) {
}
logger.info("Set up UDP network interface");
- final Tuple2<RSAPublicKey, RSAPrivateKey> keyPair = Tuple2.of(getPublicNodeId().publicKey,
+ final Tuple2<RSAPublicKey, RSAPrivateKey> keyPair = Tuple2.of(getRemoteNodeAddress().publicKey,
getPrivateNodeId().privateKey);
final TrNetworkInterface uni = new UdpNetworkInterface(config.udp, keyPair);
trNet = new TrNet(this, uni, config.capabilities.allowsUnsolicitiedInbound);
@@ -87,7 +86,7 @@ private void registerSessions() {
return Lists.newArrayList(publicNodeIdsDir.listFiles());
}
- public File getFileForPublicNode(final TrRemoteAddress addr) {
+ public File getFileForPublicNode(final PhysicalNetworkLocation addr) {
final int hc = Math.abs(addr.hashCode());
return new File(publicNodeIdsDir, "pn-" + hc + ".dat");
}
@@ -100,12 +99,12 @@ public void modifyPrivateNodeId(final ModifyBlock<PrivateNodeId> mb) {
Persistence.loadAndModify(PrivateNodeId.class, privNodeIdFile, mb);
}
- public PublicNodeId getPublicNodeId() {
- return Persistence.loadReadOnly(PublicNodeId.class, pubNodeIdFile);
+ public RemoteNodeAddress getRemoteNodeAddress() {
+ return Persistence.loadReadOnly(RemoteNodeAddress.class, pubNodeIdFile);
}
- public void modifyPublicNodeId(final ModifyBlock<PublicNodeId> mb) {
- Persistence.loadAndModify(PublicNodeId.class, pubNodeIdFile, mb);
+ public void modifyPublicNodeId(final ModifyBlock<RemoteNodeAddress> mb) {
+ Persistence.loadAndModify(RemoteNodeAddress.class, pubNodeIdFile, mb);
}
public final TrPeerManager peerManager;
@@ -115,77 +114,20 @@ public void modifyPublicNodeId(final ModifyBlock<PublicNodeId> mb) {
public TrNet trNet;
public static class PrivateNodeId {
- public static Tuple2<PrivateNodeId, PublicNodeId> generate() {
+ public static Tuple2<PrivateNodeId, RemoteNodeAddress> generate() {
final PrivateNodeId privateNodeId = new PrivateNodeId();
- final PublicNodeId publicNodeId = new PublicNodeId();
+ final RemoteNodeAddress remoteNodeAddress = new RemoteNodeAddress();
- publicNodeId.address = null;
+ remoteNodeAddress.location = null;
final Tuple2<RSAPublicKey, RSAPrivateKey> kp = TrCrypto.createRsaKeyPair();
- publicNodeId.publicKey = kp.a;
+ remoteNodeAddress.publicKey = kp.a;
privateNodeId.privateKey = kp.b;
- return Tuple2.of(privateNodeId, publicNodeId);
+ return Tuple2.of(privateNodeId, remoteNodeAddress);
}
public RSAPrivateKey privateKey;
}
-
- public static class PublicNodeIdInfo {
- public PublicNodeId id;
- public int connectionAttempts = 0;
- public int connectionFailures = 0;
- }
-
- public static class PublicNodeId {
- public TrRemoteAddress address;
- public RSAPublicKey publicKey;
-
- public PublicNodeId() {
-
- }
-
- public PublicNodeId(final TrRemoteAddress address,final RSAPublicKey publicKey) {
- this.address = address;
- this.publicKey = publicKey;
-
- }
-
-
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((address == null) ? 0 : address.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (!(obj instanceof PublicNodeId))
- return false;
- final PublicNodeId other = (PublicNodeId) obj;
- if (address == null) {
- if (other.address != null)
- return false;
- } else if (!address.equals(other.address))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("PublicNodeId [address=");
- builder.append(address);
- builder.append("]");
- return builder.toString();
- }
- }
}
View
2  src/main/java/tahrir/io/net/TrRemoteAddress.java → ...n/java/tahrir/io/net/PhysicalNetworkLocation.java
@@ -1,6 +1,6 @@
package tahrir.io.net;
-public interface TrRemoteAddress {
+public interface PhysicalNetworkLocation {
@Override
public boolean equals(Object other);
View
24 src/main/java/tahrir/io/net/TrNet.java
@@ -28,9 +28,9 @@ private static final int hashCode(final Method method) {
private final Map<Class<? extends TrSession>, Class<? extends TrSessionImpl>> classesByInterface = Maps
.newHashMap();
- private final ConcurrentLinkedQueue<Function<TrRemoteAddress, Void>> connectedListeners = new ConcurrentLinkedQueue<Function<TrRemoteAddress, Void>>();
+ private final ConcurrentLinkedQueue<Function<PhysicalNetworkLocation, Void>> connectedListeners = new ConcurrentLinkedQueue<Function<PhysicalNetworkLocation, Void>>();
- private final ConcurrentLinkedQueue<Function<TrRemoteAddress, Void>> disconnectedListeners = new ConcurrentLinkedQueue<Function<TrRemoteAddress, Void>>();
+ private final ConcurrentLinkedQueue<Function<PhysicalNetworkLocation, Void>> disconnectedListeners = new ConcurrentLinkedQueue<Function<PhysicalNetworkLocation, Void>>();
private static final Logger logger = LoggerFactory.getLogger(TrNet.class);
@@ -47,7 +47,7 @@ public void onEviction(final Tuple2<String, Integer> sessionInfo, final TrSessio
private final TrNode trNode;
- private final Map<Class<? extends TrRemoteAddress>, TrNetworkInterface> interfacesByAddressType;
+ private final Map<Class<? extends PhysicalNetworkLocation>, TrNetworkInterface> interfacesByAddressType;
public TrNet(final TrNode trNode, final TrNetworkInterface i, final boolean allowUnilateral) {
this(trNode, Collections.singleton(i), allowUnilateral);
@@ -67,11 +67,11 @@ public TrNet(final TrNode trNode, final Iterable<TrNetworkInterface> interfaces,
}
}
- public void addConnectedListener(final Function<TrRemoteAddress, Void> connectedListener) {
+ public void addConnectedListener(final Function<PhysicalNetworkLocation, Void> connectedListener) {
connectedListeners.add(connectedListener);
}
- public void addDisconnectedListener(final Function<TrRemoteAddress, Void> disconnectedListener) {
+ public void addDisconnectedListener(final Function<PhysicalNetworkLocation, Void> disconnectedListener) {
disconnectedListeners.add(disconnectedListener);
}
@@ -142,11 +142,11 @@ public void registerSessionClass(final Class<? extends TrSession> iface, final C
}
}
}
- public boolean removeConnectedListener(final Function<TrRemoteAddress, Void> connectedListener) {
+ public boolean removeConnectedListener(final Function<PhysicalNetworkLocation, Void> connectedListener) {
return connectedListeners.remove(connectedListener);
}
- public boolean removeDisconnectedListener(final Function<TrRemoteAddress, Void> disconnectedListener) {
+ public boolean removeDisconnectedListener(final Function<PhysicalNetworkLocation, Void> disconnectedListener) {
return disconnectedListeners.remove(disconnectedListener);
}
@@ -253,7 +253,7 @@ public void write(final DataOutputStream dos) throws IOException {
}
private final class TrNetMessageListener implements TrMessageListener {
- public void received(final TrNetworkInterface iFace, final TrRemoteAddress sender,
+ public void received(final TrNetworkInterface iFace, final PhysicalNetworkLocation sender,
final ByteArraySegment message) {
final DataInputStream dis = message.toDataInputStream();
try {
@@ -304,14 +304,14 @@ public void received(final TrNetworkInterface iFace, final TrRemoteAddress sende
public class ConnectionManager {
- private final Map<TrRemoteAddress, ConnectionInfo> connections = new MapMaker().makeMap();
+ private final Map<PhysicalNetworkLocation, ConnectionInfo> connections = new MapMaker().makeMap();
- public TrRemoteConnection getConnection(final TrRemoteAddress address, final RSAPublicKey pubKey,
+ public TrRemoteConnection getConnection(final PhysicalNetworkLocation address, final RSAPublicKey pubKey,
final boolean unilateral, final String userLabel) {
return getConnection(address, pubKey, unilateral, userLabel, TrUtils.noopRunnable);
}
- public TrRemoteConnection getConnection(final TrRemoteAddress address, final RSAPublicKey pubKey,
+ public TrRemoteConnection getConnection(final PhysicalNetworkLocation address, final RSAPublicKey pubKey,
final boolean unilateral, final String userLabel, final Runnable disconnectCallback) {
ConnectionInfo ci = connections.get(address);
if (ci == null) {
@@ -337,7 +337,7 @@ public void run() {
return ci.remoteConnection;
}
- public void noLongerNeeded(final TrRemoteAddress address, final String userLabel) {
+ public void noLongerNeeded(final PhysicalNetworkLocation address, final String userLabel) {
final ConnectionInfo ci = connections.get(address);
ci.interests.remove(userLabel);
if (ci.interests.isEmpty()) {
View
10 src/main/java/tahrir/io/net/TrNetworkInterface.java
@@ -29,7 +29,7 @@ public void sent() {
protected volatile TrMessageListener newConnectionListener = null;
- public abstract TrRemoteConnection connect(final TrRemoteAddress remoteAddress, final RSAPublicKey remotePubKey,
+ public abstract TrRemoteConnection connect(final PhysicalNetworkLocation remoteAddress, final RSAPublicKey remotePubKey,
final TrMessageListener listener, final Function<TrRemoteConnection, Void> connectedCallback,
final Runnable disconnectedCallback, boolean unilateral);
@@ -38,12 +38,12 @@ public abstract TrRemoteConnection connect(final TrRemoteAddress remoteAddress,
@Override
public abstract String toString();
- protected abstract Class<? extends TrRemoteAddress> getAddressClass();
+ protected abstract Class<? extends PhysicalNetworkLocation> getAddressClass();
- protected void sendTo(final TrRemoteAddress recepient, final ByteArraySegment message, final double priority) {
+ public void sendTo(final PhysicalNetworkLocation recepient, final ByteArraySegment message, final double priority) {
sendTo(recepient, message, null, priority);
}
- protected abstract void sendTo(TrRemoteAddress recepient, ByteArraySegment message, TrSentListener sentListener,
+ protected abstract void sendTo(PhysicalNetworkLocation recepient, ByteArraySegment message, TrSentListener sentListener,
double priority);
public void allowUnsolicitedInbound(final TrMessageListener newConnectionListener) {
if (this.newConnectionListener != null)
@@ -55,7 +55,7 @@ public void disallowUnsolicitedInbound() {
newConnectionListener = null;
}
public static interface TrMessageListener {
- public void received(TrNetworkInterface iFace, TrRemoteAddress sender, ByteArraySegment message);
+ public void received(TrNetworkInterface iFace, PhysicalNetworkLocation sender, ByteArraySegment message);
}
public static interface TrSentListener {
View
55 src/main/java/tahrir/peerManager/TrPeerManager.java → src/main/java/tahrir/io/net/TrPeerManager.java
@@ -1,29 +1,22 @@
-package tahrir.peerManager;
+package tahrir.io.net;
import java.io.File;
-import java.util.ArrayList;
-import java.util.Map;
+import java.util.*;
import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
+
+import com.google.common.base.*;
+import com.google.common.collect.MapMaker;
import net.sf.doodleproject.numerics4j.random.BetaRandomVariable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.slf4j.*;
-import tahrir.TrNode;
-import tahrir.TrNode.PublicNodeId;
-import tahrir.io.net.TrRemoteAddress;
+import tahrir.*;
+import tahrir.io.net.TrPeerManager.TrPeerInfo.Assimilation;
import tahrir.io.net.sessions.AssimilateSessionImpl;
-import tahrir.peerManager.TrPeerManager.TrPeerInfo.Assimilation;
-import tahrir.tools.Persistence;
+import tahrir.tools.*;
import tahrir.tools.Persistence.Modified;
-import tahrir.tools.TrUtils;
-
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.collect.MapMaker;
public class TrPeerManager {
public static final double RECENTLY_ATTEMPTED_PENALTY = 1.3;
@@ -33,7 +26,7 @@
public ConcurrentLinkedQueue<TrPeerInfo> lastAttemptedRelays = new ConcurrentLinkedQueue<TrPeerInfo>();
- public Map<TrRemoteAddress, TrPeerInfo> peers = new MapMaker().makeMap();
+ public Map<PhysicalNetworkLocation, TrPeerInfo> peers = new MapMaker().makeMap();
public final String trNetLabel;
private final TrNode node;
@@ -56,14 +49,14 @@ public void run() {
}
}
- public void addNewPeer(final PublicNodeId pubNodeId, final Capabilities capabilities) {
+ public void addNewPeer(final RemoteNodeAddress pubNodeId, final Capabilities capabilities) {
final TrPeerInfo tpi = new TrPeerInfo(pubNodeId);
tpi.capabilities = capabilities;
- peers.put(pubNodeId.address, tpi);
- node.trNet.connectionManager.getConnection(pubNodeId.address, pubNodeId.publicKey, false, trNetLabel, new Runnable() {
+ peers.put(pubNodeId.location, tpi);
+ node.trNet.connectionManager.getConnection(pubNodeId.location, pubNodeId.publicKey, false, trNetLabel, new Runnable() {
public void run() {
- peers.remove(pubNodeId.address);
+ peers.remove(pubNodeId.location);
}
});
}
@@ -90,7 +83,7 @@ public TrPeerInfo getPeerForAssimilation() {
globalSuccessTime.sample(ifo.assimilation.successTimeSqrt.mean());
}
}
- for (final Entry<TrRemoteAddress, TrPeerInfo> e : peers.entrySet()) {
+ for (final Entry<PhysicalNetworkLocation, TrPeerInfo> e : peers.entrySet()) {
final double guessFailureProb = e.getValue().assimilation.successRate.getBetaRandom();
double guessSuccessTime;
// If we don't have at least 2 samples, use our global success
@@ -136,7 +129,7 @@ public void maintainance() {
}
}
- public void reportAssimilationFailure(final TrRemoteAddress addr) {
+ public void reportAssimilationFailure(final PhysicalNetworkLocation addr) {
updatePeerInfo(addr, new Function<TrPeerManager.TrPeerInfo, Void>() {
public Void apply(final TrPeerInfo peerInfo) {
@@ -153,7 +146,7 @@ public Void apply(final TrPeerInfo peerInfo) {
});
}
- public void reportAssimilationSuccess(final TrRemoteAddress addr, final long timeMS) {
+ public void reportAssimilationSuccess(final PhysicalNetworkLocation addr, final long timeMS) {
updatePeerInfo(addr, new Function<TrPeerManager.TrPeerInfo, Void>() {
public Void apply(final TrPeerInfo peerInfo) {
@@ -172,7 +165,7 @@ public Void apply(final TrPeerInfo peerInfo) {
* @param addr
* @param updateFunction
*/
- public void updatePeerInfo(final TrRemoteAddress addr, final Function<TrPeerInfo, Void> updateFunction) {
+ public void updatePeerInfo(final PhysicalNetworkLocation addr, final Function<TrPeerInfo, Void> updateFunction) {
final File pubNodeFile = node.getFileForPublicNode(addr);
if (pubNodeFile.exists()) {
Persistence.loadAndModify(TrPeerInfo.class, pubNodeFile, new Persistence.ModifyBlock<TrPeerInfo>() {
@@ -287,15 +280,15 @@ public void sample(final double value) {
public static class TrPeerInfo {
public Assimilation assimilation = new Assimilation();
public Capabilities capabilities;
- public PublicNodeId publicNodeId;
+ public RemoteNodeAddress remoteNodeAddress;
// To allow deserialization
public TrPeerInfo() {
}
- public TrPeerInfo(final PublicNodeId publicNodeId) {
- this.publicNodeId = publicNodeId;
+ public TrPeerInfo(final RemoteNodeAddress remoteNodeAddress) {
+ this.remoteNodeAddress = remoteNodeAddress;
}
public static class Assimilation {
@@ -307,8 +300,8 @@ public TrPeerInfo(final PublicNodeId publicNodeId) {
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
- builder.append("TrPeerInfo [publicNodeId=");
- builder.append(publicNodeId);
+ builder.append("TrPeerInfo [remoteNodeAddress=");
+ builder.append(remoteNodeAddress);
builder.append("]");
return builder.toString();
}
View
6 src/main/java/tahrir/io/net/TrRemoteConnection.java
@@ -12,12 +12,12 @@
public abstract class TrRemoteConnection {
protected final TrMessageListener listener;
protected final Function<TrRemoteConnection, Void> connectedCallback;
- protected final TrRemoteAddress remoteAddress;
+ protected final PhysicalNetworkLocation remoteAddress;
protected RSAPublicKey remotePubKey;
protected final Runnable disconnectedCallback;
protected final boolean unilateralOutbound;
- protected TrRemoteConnection(final TrRemoteAddress remoteAddress, final RSAPublicKey remotePubKey,
+ protected TrRemoteConnection(final PhysicalNetworkLocation remoteAddress, final RSAPublicKey remotePubKey,
final TrMessageListener listener, final Function<TrRemoteConnection, Void> connectedCallback,
final Runnable disconnectedCallback, final boolean unilateralOutbound) {
this.remoteAddress = remoteAddress;
@@ -33,7 +33,7 @@ protected boolean isUnilateralInbound() {
return remotePubKey == null;
}
- public TrRemoteAddress getRemoteAddress() {
+ public PhysicalNetworkLocation getRemoteAddress() {
return remoteAddress;
}
View
20 src/main/java/tahrir/io/net/TrSessionImpl.java
@@ -7,11 +7,11 @@
import org.slf4j.*;
import tahrir.TrNode;
-import tahrir.peerManager.TrPeerManager.TrPeerInfo;
+import tahrir.io.net.TrPeerManager.TrPeerInfo;
public abstract class TrSessionImpl implements TrSession {
protected Logger logger;
- public static final ThreadLocal<TrRemoteAddress> sender = new ThreadLocal<TrRemoteAddress>();
+ public static final ThreadLocal<PhysicalNetworkLocation> sender = new ThreadLocal<PhysicalNetworkLocation>();
protected final int sessionId;
protected final TrNode node;
protected final TrNet trNet;
@@ -26,29 +26,29 @@ public TrSessionImpl(final Integer sessionId, final TrNode node, final TrNet trN
}
protected TrRemoteConnection connection(final TrPeerInfo peerInfo) {
- return connection(peerInfo.publicNodeId.address, peerInfo.publicNodeId.publicKey, peerInfo.capabilities.allowsUnsolicitiedInbound);
+ return connection(peerInfo.remoteNodeAddress.location, peerInfo.remoteNodeAddress.publicKey, peerInfo.capabilities.allowsUnsolicitiedInbound);
}
- public TrRemoteAddress sender() {
- final TrRemoteAddress r = sender.get();
+ public PhysicalNetworkLocation sender() {
+ final PhysicalNetworkLocation r = sender.get();
if (r == null)
throw new RuntimeException("No sender stored in this thread. Is this a local Session? Are you calling getSender() from within a callback? In either case, don't!");
else
return r;
}
- private final Set<TrRemoteAddress> toUnregister = Collections.synchronizedSet(new HashSet<TrRemoteAddress>());
+ private final Set<PhysicalNetworkLocation> toUnregister = Collections.synchronizedSet(new HashSet<PhysicalNetworkLocation>());
private final String userLabel;
- protected final TrRemoteConnection connection(final TrRemoteAddress address) {
+ protected final TrRemoteConnection connection(final PhysicalNetworkLocation address) {
return connection(address, null, false);
}
- protected final TrRemoteConnection connection(final TrRemoteAddress address, final boolean unilateral) {
+ protected final TrRemoteConnection connection(final PhysicalNetworkLocation address, final boolean unilateral) {
return connection(address, null, unilateral);
}
- protected final TrRemoteConnection connection(final TrRemoteAddress address,
+ protected final TrRemoteConnection connection(final PhysicalNetworkLocation address,
final RSAPublicKey pubKey,
final boolean unilateral) {
toUnregister.add(address);
@@ -75,7 +75,7 @@ public void registerFailureListener(final Runnable listener) {
}
protected final void terminate() {
- for (final TrRemoteAddress ra : toUnregister) {
+ for (final PhysicalNetworkLocation ra : toUnregister) {
trNet.connectionManager.noLongerNeeded(ra, userLabel);
}
for (final Runnable r : terminatedCallbacks) {
View
8 src/main/java/tahrir/io/net/sessions/AssimilateSession.java
@@ -3,7 +3,7 @@
import java.security.interfaces.RSAPublicKey;
import tahrir.io.net.*;
-import tahrir.peerManager.TrPeerManager.Capabilities;
+import tahrir.io.net.TrPeerManager.Capabilities;
/*
* This is the assimilation procedure, we have a requestor, who needs a new connection, zero or more
@@ -22,16 +22,16 @@
public interface AssimilateSession extends TrSession {
@Priority(TrNetworkInterface.ASSIMILATION_PRIORITY)
- public void yourAddressIs(final TrRemoteAddress address);
+ public void yourAddressIs(final PhysicalNetworkLocation address);
@Priority(TrNetworkInterface.ASSIMILATION_PRIORITY)
public void requestNewConnection(final RSAPublicKey requestorPubkey);
@Priority(TrNetworkInterface.ASSIMILATION_PRIORITY)
- public void requestNewConnection(TrRemoteAddress requestor, final RSAPublicKey requestorPubkey);
+ public void requestNewConnection(PhysicalNetworkLocation requestor, final RSAPublicKey requestorPubkey);
@Priority(TrNetworkInterface.ASSIMILATION_PRIORITY)
- public void acceptNewConnection(TrRemoteAddress acceptor, final RSAPublicKey acceptorPubkey);
+ public void acceptNewConnection(PhysicalNetworkLocation acceptor, final RSAPublicKey acceptorPubkey);
@Priority(TrNetworkInterface.ASSIMILATION_PRIORITY)
public void myCapabilitiesAre(Capabilities myCapabilities);
View
58 src/main/java/tahrir/io/net/sessions/AssimilateSessionImpl.java
@@ -8,11 +8,9 @@
import org.slf4j.*;
import tahrir.*;
-import tahrir.TrNode.PublicNodeId;
import tahrir.io.net.*;
-import tahrir.peerManager.*;
-import tahrir.peerManager.TrPeerManager.Capabilities;
-import tahrir.peerManager.TrPeerManager.TrPeerInfo;
+import tahrir.io.net.TrPeerManager.Capabilities;
+import tahrir.io.net.TrPeerManager.TrPeerInfo;
import tahrir.tools.Persistence.Modified;
import tahrir.tools.Persistence.ModifyBlock;
import tahrir.tools.*;
@@ -25,10 +23,10 @@
private boolean locallyInitiated;
private AssimilateSession pubNodeSession;
private AssimilateSession receivedRequestFrom;
- private TrRemoteAddress acceptorAddress;
+ private PhysicalNetworkLocation acceptorAddress;
private RSAPublicKey acceptorPubkey;
private Capabilities remoteCapabilities;
- private TrRemoteAddress requestorAddress;
+ private PhysicalNetworkLocation requestorAddress;
private RSAPublicKey requestorPubkey;
private long requestNewConnectionTime;
private ScheduledFuture<?> requestNewConnectionFuture;
@@ -46,43 +44,43 @@ public void startAssimilation(final Runnable onFailure, final TrPeerInfo assimil
requestNewConnectionFuture = TrUtils.executor.schedule(new Runnable() {
public void run() {
- node.peerManager.updatePeerInfo(relay.publicNodeId.address, new Function<TrPeerManager.TrPeerInfo, Void>() {
+ node.peerManager.updatePeerInfo(relay.remoteNodeAddress.location, new Function<TrPeerManager.TrPeerInfo, Void>() {
public Void apply(final TrPeerInfo tpi) {
if (logger.isDebugEnabled()) {
- logger.debug("Reporting assimilation failure for "+relay.publicNodeId.address);
+ logger.debug("Reporting assimilation failure for "+relay.remoteNodeAddress.location);
}
- node.peerManager.reportAssimilationFailure(relay.publicNodeId.address);
+ node.peerManager.reportAssimilationFailure(relay.remoteNodeAddress.location);
return null;
}
});
}
}, RELAY_ASSIMILATION_TIMEOUT_SECONDS, TimeUnit.SECONDS);
locallyInitiated = true;
- pubNodeSession = this.remoteSession(AssimilateSession.class, this.connection(assimilateVia.publicNodeId.address, assimilateVia.publicNodeId.publicKey, true));
+ pubNodeSession = this.remoteSession(AssimilateSession.class, this.connection(assimilateVia.remoteNodeAddress.location, assimilateVia.remoteNodeAddress.publicKey, true));
pubNodeSession.registerFailureListener(onFailure);
- pubNodeSession.requestNewConnection(node.getPublicNodeId().publicKey);
+ pubNodeSession.requestNewConnection(node.getRemoteNodeAddress().publicKey);
}
- public void yourAddressIs(final TrRemoteAddress address) {
+ public void yourAddressIs(final PhysicalNetworkLocation address) {
if (!locallyInitiated) {
logger.warn("Received yourAddressIs() from {}, yet this AssimilateSession was not locally initiated",
sender());
return;
}
- if (!sender().equals(relay.publicNodeId.address)) {
+ if (!sender().equals(relay.remoteNodeAddress.location)) {
logger.warn("Received yourAddressIs() from {}, yet the public node we expected it from was {}, ignoring",
- sender(), relay.publicNodeId.address);
+ sender(), relay.remoteNodeAddress.location);
return;
}
if (logger.isDebugEnabled()) {
logger.debug(sender()+" told us that our external address is "+address);
}
- node.modifyPublicNodeId(new ModifyBlock<TrNode.PublicNodeId>() {
+ node.modifyPublicNodeId(new ModifyBlock<RemoteNodeAddress>() {
- public void run(final PublicNodeId object, final Modified modified) {
- object.address = address;
+ public void run(final RemoteNodeAddress object, final Modified modified) {
+ object.location = address;
}
});
}
@@ -92,8 +90,8 @@ public void requestNewConnection(final RSAPublicKey requestorPubkey) {
requestNewConnection(null, requestorPubkey);
}
- public void requestNewConnection(TrRemoteAddress requestorAddress, final RSAPublicKey requestorPubkey) {
- final TrRemoteAddress senderFV = sender();
+ public void requestNewConnection(PhysicalNetworkLocation requestorAddress, final RSAPublicKey requestorPubkey) {
+ final PhysicalNetworkLocation senderFV = sender();
if (locallyInitiated) {
logger.warn("Received requestNewConnection() from {}, but the session was locally initiated, ignoring",
senderFV);
@@ -115,8 +113,8 @@ public void requestNewConnection(TrRemoteAddress requestorAddress, final RSAPubl
logger.debug("Accepting {} as new peer", requestorAddress);
}
// We're going to accept them
- final PublicNodeId publicNodeId = node.getPublicNodeId();
- receivedRequestFrom.acceptNewConnection(publicNodeId.address, publicNodeId.publicKey);
+ final RemoteNodeAddress remoteNodeAddress = node.getRemoteNodeAddress();
+ receivedRequestFrom.acceptNewConnection(remoteNodeAddress.location, remoteNodeAddress.publicKey);
final AssimilateSession requestorSession = remoteSession(AssimilateSession.class,
connection(this.requestorAddress, requestorPubkey, false));
requestorSession.myCapabilitiesAre(node.config.capabilities);
@@ -130,13 +128,13 @@ public void requestNewConnection(TrRemoteAddress requestorAddress, final RSAPubl
requestNewConnectionFuture = TrUtils.executor.schedule(new Runnable() {
public void run() {
- node.peerManager.updatePeerInfo(relay.publicNodeId.address, new Function<TrPeerManager.TrPeerInfo, Void>() {
+ node.peerManager.updatePeerInfo(relay.remoteNodeAddress.location, new Function<TrPeerManager.TrPeerInfo, Void>() {
public Void apply(final TrPeerInfo tpi) {
if (logger.isDebugEnabled()) {
logger.debug("Reporting assimilation failure to peerManager after sending assimilation request to {}", relay);
}
- node.peerManager.reportAssimilationFailure(relay.publicNodeId.address);
+ node.peerManager.reportAssimilationFailure(relay.remoteNodeAddress.location);
return null;
}
});
@@ -151,7 +149,7 @@ public void run() {
if (logger.isDebugEnabled()) {
logger.debug("Reporting assimilation failure to peerManager after sending assimilation request to {}, and then trying again", relay);
}
- node.peerManager.reportAssimilationFailure(relay.publicNodeId.address);
+ node.peerManager.reportAssimilationFailure(relay.remoteNodeAddress.location);
// Note: Important to use requestAddress field rather than
// the parameter because the parameter may be null
AssimilateSessionImpl.this.requestNewConnection(AssimilateSessionImpl.this.requestorAddress,
@@ -163,18 +161,18 @@ public void run() {
}
}
- public void acceptNewConnection(final TrRemoteAddress acceptor, final RSAPublicKey acceptorPubkey) {
- if (!sender().equals(relay.publicNodeId.address)) {
- logger.warn("Received acceptNewConnection() from {}, but was expecting it from {}", sender(), relay.publicNodeId.address);
+ public void acceptNewConnection(final PhysicalNetworkLocation acceptor, final RSAPublicKey acceptorPubkey) {
+ if (!sender().equals(relay.remoteNodeAddress.location)) {
+ logger.warn("Received acceptNewConnection() from {}, but was expecting it from {}", sender(), relay.remoteNodeAddress.location);
}
if (logger.isDebugEnabled()) {
logger.debug("{} is accepting assimiliation request", acceptor);
}
requestNewConnectionFuture.cancel(false);
- node.peerManager.updatePeerInfo(relay.publicNodeId.address, new Function<TrPeerManager.TrPeerInfo, Void>() {
+ node.peerManager.updatePeerInfo(relay.remoteNodeAddress.location, new Function<TrPeerManager.TrPeerInfo, Void>() {
public Void apply(final TrPeerInfo tpi) {
- node.peerManager.reportAssimilationSuccess(relay.publicNodeId.address, System.currentTimeMillis()
+ node.peerManager.reportAssimilationSuccess(relay.remoteNodeAddress.location, System.currentTimeMillis()
- requestNewConnectionTime);
return null;
}
@@ -217,7 +215,7 @@ private void addNewConnection() {
if (logger.isDebugEnabled()) {
logger.debug("Adding new connection to {}", acceptorAddress);
}
- node.peerManager.addNewPeer(new PublicNodeId(locallyInitiated ? acceptorAddress : requestorAddress,
+ node.peerManager.addNewPeer(new RemoteNodeAddress(locallyInitiated ? acceptorAddress : requestorAddress,
locallyInitiated ? acceptorPubkey : requestorPubkey), remoteCapabilities);
}
}
View
53 src/main/java/tahrir/io/net/udpV1/UdpNetworkInterface.java
@@ -1,29 +1,19 @@
package tahrir.io.net.udpV1;
import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.SocketException;
-import java.net.SocketTimeoutException;
-import java.security.interfaces.RSAPrivateKey;
-import java.security.interfaces.RSAPublicKey;
+import java.net.*;
+import java.security.interfaces.*;
import java.util.Map;
-import java.util.concurrent.PriorityBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import tahrir.io.net.TrNetworkInterface;
-import tahrir.io.net.TrRemoteAddress;
-import tahrir.io.net.TrRemoteConnection;
-import tahrir.tools.ByteArraySegment;
-import tahrir.tools.TrUtils;
-import tahrir.tools.Tuple2;
+import java.util.concurrent.*;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
+import org.slf4j.*;
+
+import tahrir.io.net.*;
+import tahrir.tools.*;
+
/**
* @author Ian Clarke <ian.clarke@gmail.com>
*
@@ -34,7 +24,7 @@
private final org.slf4j.Logger logger;
public final RSAPrivateKey myPrivateKey;
public final RSAPublicKey myPublicKey;
- public Map<TrRemoteAddress, UdpRemoteConnection> remoteConnections = Maps.newConcurrentMap();
+ public Map<PhysicalNetworkLocation, UdpRemoteConnection> remoteConnections = Maps.newConcurrentMap();
private final DatagramSocket datagramSocket;
private final PriorityBlockingQueue<QueuedPacket> outbox = new PriorityBlockingQueue<UdpNetworkInterface.QueuedPacket>();
@@ -71,7 +61,7 @@ public UdpNetworkInterface(final UNIConfig config, final Tuple2<RSAPublicKey, RS
* @param unilateral Is the other node trying to connect back to us?
*/
@Override
- public TrRemoteConnection connect(final TrRemoteAddress remoteAddress,
+ public TrRemoteConnection connect(final PhysicalNetworkLocation remoteAddress,
final RSAPublicKey remotePubKey,
final tahrir.io.net.TrNetworkInterface.TrMessageListener listener,
final Function<TrRemoteConnection, Void> connectedCallback,
@@ -82,7 +72,7 @@ public TrRemoteConnection connect(final TrRemoteAddress remoteAddress,
if (conn != null)
return conn;
- conn = new UdpRemoteConnection(this, (UdpRemoteAddress) remoteAddress, remotePubKey, listener,
+ conn = new UdpRemoteConnection(this, (UdpNetworkLocation) remoteAddress, remotePubKey, listener,
connectedCallback,
disconnectedCallback, unilateral);
remoteConnections.put(remoteAddress, conn);
@@ -90,15 +80,15 @@ public TrRemoteConnection connect(final TrRemoteAddress remoteAddress,
}
@Override
- protected void sendTo(final TrRemoteAddress recepient, final ByteArraySegment message, final double priority) {
+ public void sendTo(final PhysicalNetworkLocation recepient, final ByteArraySegment message, final double priority) {
// We redeclare this to make it visible in this package
super.sendTo(recepient, message, priority);
}
@Override
- protected void sendTo(final TrRemoteAddress recepient_, final ByteArraySegment encryptedMessage,
+ protected void sendTo(final PhysicalNetworkLocation recepient_, final ByteArraySegment encryptedMessage,
final tahrir.io.net.TrNetworkInterface.TrSentListener sentListener, final double priority) {
- final UdpRemoteAddress recepient = (UdpRemoteAddress) recepient_;
+ final UdpNetworkLocation recepient = (UdpNetworkLocation) recepient_;
assert encryptedMessage.length <= MAX_PACKET_SIZE_BYTES : "Packet length " + encryptedMessage.length
+ " greater than " + MAX_PACKET_SIZE_BYTES;
final QueuedPacket qp = new QueuedPacket(recepient, encryptedMessage, sentListener, priority);
@@ -119,8 +109,8 @@ public String toString() {
}
@Override
- protected Class<? extends TrRemoteAddress> getAddressClass() {
- return UdpRemoteAddress.class;
+ protected Class<? extends PhysicalNetworkLocation> getAddressClass() {
+ return UdpNetworkLocation.class;
}
protected void setSimPercentageLoss(final Double percentage) {
@@ -135,12 +125,12 @@ protected void setSimPercentageLoss(final Double percentage) {
private static class QueuedPacket implements Comparable<QueuedPacket> {
- private final UdpRemoteAddress addr;
+ private final UdpNetworkLocation addr;
private final ByteArraySegment data;
private final double priority;
private final tahrir.io.net.TrNetworkInterface.TrSentListener sentListener;
- public QueuedPacket(final UdpRemoteAddress addr, final ByteArraySegment encryptedMessage,
+ public QueuedPacket(final UdpNetworkLocation addr, final ByteArraySegment encryptedMessage,
final tahrir.io.net.TrNetworkInterface.TrSentListener sentListener, final double priority) {
this.addr = addr;
data = encryptedMessage;
@@ -176,12 +166,7 @@ public void run() {
try {
parent.datagramSocket.receive(dp);
- if (isPacketToDrop()) {
- logger.debug("Dropping packet");
- continue;
- }
-
- final UdpRemoteAddress ura = new UdpRemoteAddress(dp.getAddress(), dp.getPort());
+ final UdpNetworkLocation ura = new UdpNetworkLocation(dp.getAddress(), dp.getPort());
UdpRemoteConnection connection = parent.remoteConnections.get(ura);
logger.debug("Retrieving "+ura+" (hash:"+ura.hashCode()+" from "+parent.remoteConnections+" => "+connection);
View
10 ...in/java/tahrir/io/net/udpV1/UdpRemoteAddress.java → .../java/tahrir/io/net/udpV1/UdpNetworkLocation.java
@@ -2,13 +2,13 @@
import java.net.InetAddress;
-import tahrir.io.net.TrRemoteAddress;
+import tahrir.io.net.PhysicalNetworkLocation;
-public class UdpRemoteAddress implements TrRemoteAddress {
+public class UdpNetworkLocation implements PhysicalNetworkLocation {
public final InetAddress inetAddress;
public final int port;
- public UdpRemoteAddress(final InetAddress inetAddress, final int port) {
+ public UdpNetworkLocation(final InetAddress inetAddress, final int port) {
this.inetAddress = inetAddress;
this.port = port;
}
@@ -28,9 +28,9 @@ public boolean equals(final Object obj) {
return true;
if (obj == null)
return false;
- if (!(obj instanceof UdpRemoteAddress))
+ if (!(obj instanceof UdpNetworkLocation))
return false;
- final UdpRemoteAddress other = (UdpRemoteAddress) obj;
+ final UdpNetworkLocation other = (UdpNetworkLocation) obj;
if (inetAddress == null) {
if (other.inetAddress != null)
return false;
View
6 src/main/java/tahrir/io/net/udpV1/UdpRemoteConnection.java
@@ -50,7 +50,7 @@
protected UdpRemoteConnection(
final UdpNetworkInterface iface,
- final UdpRemoteAddress remoteAddr,
+ final UdpNetworkLocation remoteAddr,
final RSAPublicKey remotePubKey,
final TrMessageListener listener,
final Function<TrRemoteConnection, Void> connectedCallback,
@@ -131,10 +131,10 @@ public boolean isConnected() {
}
- public void received(final TrNetworkInterface iFace, final TrRemoteAddress sender_,
+ public void received(final TrNetworkInterface iFace, final PhysicalNetworkLocation sender_,
ByteArraySegment message) {
logger.debug("Received message from "+sender_);
- final UdpRemoteAddress sender = (UdpRemoteAddress) sender_;
+ final UdpNetworkLocation sender = (UdpNetworkLocation) sender_;
if (inboundSymKey == null) {
logger.debug("We don't know the inboundSymKey yet, looking for it to be pre-pended to message");
inboundSymKeyEncoded = message.subsegment(0, 256);
View
4 src/main/java/tahrir/io/serialization/TrSerializer.java
@@ -9,7 +9,7 @@
import com.google.common.collect.Maps;
-import tahrir.io.net.TrRemoteAddress;
+import tahrir.io.net.PhysicalNetworkLocation;
import tahrir.io.serialization.serializers.*;
import tahrir.tools.ByteArraySegment;
@@ -36,7 +36,7 @@
registerSerializer(new RSAPrivateKeySerializer(), RSAPrivateKey.class);
registerSerializer(new ByteArraySegmentSerializer(), ByteArraySegment.class);
registerSerializer(new InetAddressSerializer(), InetAddress.class);
- registerSerializer(new TrRemoteAddressSerializer(), TrRemoteAddress.class);
+ registerSerializer(new NetworkLocationSerializer(), PhysicalNetworkLocation.class);
}
private static final Map<Class<?>, Map<Integer, Field>> fieldMap = Maps.newHashMap();
View
18 ...zation/serializers/TrRemoteAddressSerializer.java → ...zation/serializers/NetworkLocationSerializer.java
@@ -4,24 +4,24 @@
import java.lang.reflect.Type;
import java.net.InetAddress;
-import tahrir.io.net.TrRemoteAddress;
-import tahrir.io.net.udpV1.UdpRemoteAddress;
+import tahrir.io.net.PhysicalNetworkLocation;
+import tahrir.io.net.udpV1.UdpNetworkLocation;
import tahrir.io.serialization.*;
-public class TrRemoteAddressSerializer extends TrSerializer {
+public class NetworkLocationSerializer extends TrSerializer {
public static final byte UDP_REMOTE_ADDRESS = 0;
- public TrRemoteAddressSerializer() {
- super(TrRemoteAddress.class);
+ public NetworkLocationSerializer() {
+ super(PhysicalNetworkLocation.class);
}
@Override
- protected TrRemoteAddress deserialize(final Type type, final DataInputStream dis) throws IOException,
+ protected PhysicalNetworkLocation deserialize(final Type type, final DataInputStream dis) throws IOException,
TrSerializableException {
final byte raType = dis.readByte();
if (raType == UDP_REMOTE_ADDRESS)
- return new UdpRemoteAddress(TrSerializer.deserializeFrom(InetAddress.class, dis), dis.readInt());
+ return new UdpNetworkLocation(TrSerializer.deserializeFrom(InetAddress.class, dis), dis.readInt());
else
throw new TrSerializableException("Unrecognised TrRemoteAddress type: " + raType);
}
@@ -29,11 +29,11 @@ protected TrRemoteAddress deserialize(final Type type, final DataInputStream dis
@Override
protected void serialize(final Type type, final Object object, final DataOutputStream dos) throws IOException,
TrSerializableException {
- if (!(object instanceof UdpRemoteAddress))
+ if (!(object instanceof UdpNetworkLocation))
throw new TrSerializableException("Unrecognized TrRemoteAddress type: " + object.getClass());
else {
dos.writeByte(UDP_REMOTE_ADDRESS);
- final UdpRemoteAddress ura = (UdpRemoteAddress) object;
+ final UdpNetworkLocation ura = (UdpNetworkLocation) object;
TrSerializer.serializeTo(ura.inetAddress, dos);
dos.writeInt(ura.port);
}
View
8 src/test/java/tahrir/io/net/TrNetTest.java
@@ -62,10 +62,10 @@ public void setUpNodes() throws Exception {
trn2.registerSessionClass(TestSession.class, TestSessionImpl.class);
final TrRemoteConnection one2two = trn1.connectionManager.getConnection(
- new UdpRemoteAddress(InetAddress.getByName("127.0.0.1"), udpNetIfaceConf2.listenPort), kp2.a, false,
+ new UdpNetworkLocation(InetAddress.getByName("127.0.0.1"), udpNetIfaceConf2.listenPort), kp2.a, false,
"trn1");
final TrRemoteConnection two2one = trn2.connectionManager.getConnection(
- new UdpRemoteAddress(InetAddress.getByName("127.0.0.1"), udpNetIfaceConf1.listenPort), kp1.a, false,
+ new UdpNetworkLocation(InetAddress.getByName("127.0.0.1"), udpNetIfaceConf1.listenPort), kp1.a, false,
"trn2");
remoteSession = trn1.getOrCreateRemoteSession(TestSession.class, one2two, 1234);
@@ -122,7 +122,7 @@ public TestSessionImpl(final Integer sessionId, final TrNode node, final TrNet t
public void testMethod(final int param) {
if (param < 10) {
- final TrRemoteAddress senderRemoteAddress = sender();
+ final PhysicalNetworkLocation senderRemoteAddress = sender();
final TrRemoteConnection connectionToSender = connection(senderRemoteAddress);
final TestSession remoteSessionOnSender = remoteSession(TestSession.class, connectionToSender);
remoteSessionOnSender.testMethod(param + 1);
@@ -139,7 +139,7 @@ public void testMethod2(final LinkedList<Integer> list) {
sum += i;
}
list.add(sum);
- final TrRemoteAddress senderRemoteAddress = sender();
+ final PhysicalNetworkLocation senderRemoteAddress = sender();
final TrRemoteConnection connectionToSender = connection(senderRemoteAddress);
final TestSession remoteSessionOnSender = remoteSession(TestSession.class, connectionToSender);
remoteSessionOnSender.testMethod2(list);
View
5 src/test/java/tahrir/io/net/sessions/AssimilateTest.java
@@ -5,8 +5,7 @@
import org.testng.annotations.Test;
import tahrir.*;
-import tahrir.TrNode.PublicNodeId;
-import tahrir.peerManager.TrPeerManager;
+import tahrir.io.net.TrPeerManager;
import tahrir.tools.*;
public class AssimilateTest {
@@ -21,7 +20,7 @@ public void twoPeerTest() throws Exception {
final File seedDir = TrUtils.createTempDirectory();
final TrNode seedNode = new TrNode(seedDir, seedConfig);
- final PublicNodeId seedPublicNodeId = seedNode.getPublicNodeId();
+ final RemoteNodeAddress seedPublicNodeId = seedNode.getRemoteNodeAddress();
final File joinerDir = TrUtils.createTempDirectory();
View
11 src/test/java/tahrir/io/net/udpV1/UdpNetworkInterfaceTest.java
@@ -14,9 +14,10 @@
import tahrir.io.net.TrNetworkInterface;
import tahrir.io.net.TrNetworkInterface.TrMessageListener;
import tahrir.io.net.TrNetworkInterface.TrSentReceivedListener;
-import tahrir.io.net.TrRemoteAddress;
+import tahrir.io.net.PhysicalNetworkLocation;
import tahrir.io.net.TrRemoteConnection;
import tahrir.io.net.udpV1.UdpNetworkInterface.UNIConfig;
+import tahrir.io.net.udpV1.UdpNetworkLocation;
import tahrir.tools.ByteArraySegment;
import tahrir.tools.ByteArraySegment.ByteArraySegmentBuilder;
import tahrir.tools.Tuple2;
@@ -59,12 +60,12 @@ public void setUp() throws Exception {
conf2.maxUpstreamBytesPerSecond = 1024;
i2 = new UdpNetworkInterface(conf2, kp2);
- final UdpRemoteAddress ra1 = new UdpRemoteAddress(InetAddress.getByName("127.0.0.1"), conf1.listenPort);
- final UdpRemoteAddress ra2 = new UdpRemoteAddress(InetAddress.getByName("127.0.0.1"), conf2.listenPort);
+ final UdpNetworkLocation ra1 = new UdpNetworkLocation(InetAddress.getByName("127.0.0.1"), conf1.listenPort);
+ final UdpNetworkLocation ra2 = new UdpNetworkLocation(InetAddress.getByName("127.0.0.1"), conf2.listenPort);
final TrMessageListener noopListener = new TrMessageListener() {
- public void received(final TrNetworkInterface iFace, final TrRemoteAddress sender,
+ public void received(final TrNetworkInterface iFace, final PhysicalNetworkLocation sender,
final ByteArraySegment message) {
}
@@ -72,7 +73,7 @@ public void received(final TrNetworkInterface iFace, final TrRemoteAddress sende
listener = new TrMessageListener() {
- public void received(final TrNetworkInterface iFace, final TrRemoteAddress sender,
+ public void received(final TrNetworkInterface iFace, final PhysicalNetworkLocation sender,
final ByteArraySegment message) {
Assert.assertEquals(message, sentMessage);
receivedSuccessfully.called = true;
View
8 src/test/java/tahrir/io/serialization/SerializationTest.java
@@ -7,10 +7,10 @@
import org.testng.Assert;
import org.testng.annotations.Test;
-import tahrir.TrNode.PublicNodeId;
+import tahrir.RemoteNodeAddress;
import tahrir.io.crypto.TrCrypto;
-import tahrir.io.net.udpV1.UdpRemoteAddress;
-import tahrir.peerManager.TrPeerManager.TrPeerInfo;
+import tahrir.io.net.TrPeerManager.TrPeerInfo;
+import tahrir.io.net.udpV1.UdpNetworkLocation;
import com.google.inject.internal.*;
@@ -67,7 +67,7 @@ public void objectTypeTest() throws Exception {
@Test
public void trPeerInfoTest() throws Exception {
- final TrPeerInfo ot = new TrPeerInfo(new PublicNodeId(new UdpRemoteAddress(InetAddress.getByName("127.0.0.1"), 1234), TrCrypto.createRsaKeyPair().a));
+ final TrPeerInfo ot = new TrPeerInfo(new RemoteNodeAddress(new UdpNetworkLocation(InetAddress.getByName("127.0.0.1"), 1234), TrCrypto.createRsaKeyPair().a));
final ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
final DataOutputStream dos = new DataOutputStream(baos);
TrSerializer.serializeTo(ot, dos);

No commit comments for this range

Something went wrong with that request. Please try again.