setNodeRef(nodeRef);
}
+ public AddPeer(String identifier, NodeRef nodeRef) {
+ this(nodeRef);
+ setField("Identifier", identifier);
+ }
+
//
// PRIVATE METHODS
//
* The noderef of the peer
*/
private void setNodeRef(NodeRef nodeRef) {
- setField("lastGoodVersion", nodeRef.getLastGoodVersion().toString());
+ setField("lastGoodVersion", String.valueOf(nodeRef.getLastGoodVersion()));
setField("opennet", String.valueOf(nodeRef.isOpennet()));
setField("identity", nodeRef.getIdentity());
setField("myName", nodeRef.getMyName());
import java.util.concurrent.atomic.AtomicReference;
import net.pterodactylus.fcp.AddPeer;
+import net.pterodactylus.fcp.NodeRef;
import net.pterodactylus.fcp.Peer;
import net.pterodactylus.fcp.ProtocolError;
private final ConnectionSupplier connectionSupplier;
private final AtomicReference<File> file = new AtomicReference<>();
private final AtomicReference<URL> url = new AtomicReference<>();
+ private final AtomicReference<NodeRef> nodeRef = new AtomicReference<>();
public AddPeerCommandImpl(ExecutorService threadPool, ConnectionSupplier connectionSupplier) {
this.threadPool = MoreExecutors.listeningDecorator(threadPool);
return this::execute;
}
+ @Override
+ public Executable<Optional<Peer>> fromNodeRef(NodeRef nodeRef) {
+ this.nodeRef.set(nodeRef);
+ return this::execute;
+ }
+
private ListenableFuture<Optional<Peer>> execute() {
return threadPool.submit(this::executeSequence);
}
addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), file.get().getPath());
} else if (url.get() != null) {
addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), url.get());
+ } else {
+ addPeer = new AddPeer(new RandomIdentifierGenerator().generate(), nodeRef.get());
}
try (AddPeerSequence addPeerSequence = new AddPeerSequence()) {
return addPeerSequence.send(addPeer).get();
import java.util.concurrent.Future;
import java.util.stream.Collectors;
+import net.pterodactylus.fcp.ARK;
+import net.pterodactylus.fcp.DSAGroup;
import net.pterodactylus.fcp.FcpKeyPair;
import net.pterodactylus.fcp.Key;
import net.pterodactylus.fcp.NodeData;
+import net.pterodactylus.fcp.NodeRef;
import net.pterodactylus.fcp.Peer;
import net.pterodactylus.fcp.Priority;
import net.pterodactylus.fcp.fake.FakeTcpServer;
assertThat(peer.get().get().getIdentity().toString(), is("id1"));
}
+ @Test
+ public void defaultFcpClientCanAddPeerFromNodeRef() throws InterruptedException, ExecutionException, IOException {
+ NodeRef nodeRef = new NodeRef();
+ nodeRef.setIdentity("id1");
+ nodeRef.setName("name");
+ nodeRef.setARK(new ARK("public", "1"));
+ nodeRef.setDSAGroup(new DSAGroup("base", "prime", "subprime"));
+ nodeRef.setNegotiationTypes(new int[] { 3, 5 });
+ nodeRef.setPhysicalUDP("1.2.3.4:5678");
+ nodeRef.setDSAPublicKey("dsa-public");
+ nodeRef.setSignature("sig");
+ Future<Optional<Peer>> peer = fcpClient.addPeer().fromNodeRef(nodeRef).execute();
+ connectNode();
+ List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+ String identifier = extractIdentifier(lines);
+ assertThat(lines, matchesFcpMessage(
+ "AddPeer",
+ "Identifier=" + identifier,
+ "identity=id1",
+ "myName=name",
+ "ark.pubURI=public",
+ "ark.number=1",
+ "dsaGroup.g=base",
+ "dsaGroup.p=prime",
+ "dsaGroup.q=subprime",
+ "dsaPubKey.y=dsa-public",
+ "physical.udp=1.2.3.4:5678",
+ "auth.negTypes=3;5",
+ "sig=sig",
+ "EndMessage"
+ ));
+ fcpServer.writeLine(
+ "Peer",
+ "Identifier=" + identifier,
+ "identity=id1",
+ "opennet=false",
+ "ark.pubURI=SSK@3YEf.../ark",
+ "ark.number=78",
+ "auth.negTypes=2",
+ "version=Fred,0.7,1.0,1466",
+ "lastGoodVersion=Fred,0.7,1.0,1466",
+ "EndMessage"
+ );
+ assertThat(peer.get().get().getIdentity().toString(), is("id1"));
+ }
+
}