rename method
[jSite2.git] / src / net / pterodactylus / util / fcp / AddPeer.java
1 /**
2  * © 2008 INA Service GmbH
3  */
4 package net.pterodactylus.util.fcp;
5
6 import java.net.URL;
7
8 /**
9  * The “AddPeer” request adds a peer to the node.
10  * 
11  * @author <a href="mailto:dr@ina-germany.de">David Roden</a>
12  * @version $Id$
13  */
14 public class AddPeer extends FcpMessage {
15
16         /**
17          * Creates a new “AddPeer” request.
18          */
19         private AddPeer() {
20                 super("AddPeer");
21         }
22
23         /**
24          * Creates a new “AddPeer” request that reads the noderef of the peer from
25          * the given file.
26          * 
27          * @param file
28          *            The file to read the noderef from
29          */
30         public AddPeer(String file) {
31                 this();
32                 setField("File", file);
33         }
34
35         /**
36          * Creates a new “AddPeer” request that reads the noderef of the peer from
37          * the given URL.
38          * 
39          * @param url
40          *            The URL to read the noderef from
41          */
42         public AddPeer(URL url) {
43                 this();
44                 setField("URL", String.valueOf(url));
45         }
46
47         /**
48          * Creates a new “AddPeer” request that adds the peer given by the noderef.
49          * 
50          * @param nodeRef
51          *            The noderef of the peer
52          */
53         public AddPeer(NodeRef nodeRef) {
54                 this();
55                 setNodeRef(nodeRef);
56         }
57
58         //
59         // PRIVATE METHODS
60         //
61
62         /**
63          * Sets the noderef of the peer to add.
64          * 
65          * @param nodeRef
66          *            The noderef of the peer
67          */
68         private void setNodeRef(NodeRef nodeRef) {
69                 setField("lastGoodVersion", nodeRef.getLastGoodVersion().toString());
70                 setField("opennet", String.valueOf(nodeRef.isOpennet()));
71                 setField("identity", nodeRef.getIdentity());
72                 setField("myName", nodeRef.getMyName());
73                 setField("location", String.valueOf(nodeRef.getLocation()));
74                 setField("testnet", String.valueOf(nodeRef.isTestnet()));
75                 setField("version", String.valueOf(nodeRef.getVersion()));
76                 setField("physical.udp", nodeRef.getPhysicalUDP());
77                 setField("ark.pubURI", nodeRef.getARK().getPublicURI());
78                 setField("ark.number", String.valueOf(nodeRef.getARK().getNumber()));
79                 setField("dsaPubKey.y", nodeRef.getDSAPublicKey());
80                 setField("dsaGroup.g", nodeRef.getDSAGroup().getBase());
81                 setField("dsaGroup.p", nodeRef.getDSAGroup().getPrime());
82                 setField("dsaGroup.q", nodeRef.getDSAGroup().getSubprime());
83                 setField("auth.negTypes", FcpUtils.encodeMultiIntegerField(nodeRef.getNegotiationTypes()));
84                 setField("sig", nodeRef.getSignature());
85         }
86
87 }