Expose lots of constructors and accessors
[jFCPlib.git] / src / main / java / net / pterodactylus / fcp / AddPeer.java
1 /*
2  * jFCPlib - AddPeer.java - Copyright © 2008 David Roden
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18
19 package net.pterodactylus.fcp;
20
21 import java.net.URL;
22
23 /**
24  * The “AddPeer” request adds a peer to the node.
25  *
26  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
27  */
28 public class AddPeer extends FcpMessage {
29
30         /**
31          * Creates a new “AddPeer” request.
32          */
33         private AddPeer() {
34                 super("AddPeer");
35         }
36
37         /**
38          * Creates a new “AddPeer” request that reads the noderef of the peer from
39          * the given file.
40          *
41          * @param file
42          *            The file to read the noderef from
43          */
44         public AddPeer(String file) {
45                 this();
46                 setField("File", file);
47         }
48
49         public AddPeer(String identifier, String file) {
50                 this(file);
51                 setField("Identifier", identifier);
52         }
53
54         /**
55          * Creates a new “AddPeer” request that reads the noderef of the peer from
56          * the given URL.
57          *
58          * @param url
59          *            The URL to read the noderef from
60          */
61         public AddPeer(URL url) {
62                 this();
63                 setField("URL", String.valueOf(url));
64         }
65
66         public AddPeer(String identifier, URL url) {
67                 this(url);
68                 setField("Identifier", identifier);
69         }
70
71         /**
72          * Creates a new “AddPeer” request that adds the peer given by the noderef.
73          *
74          * @param nodeRef
75          *            The noderef of the peer
76          */
77         public AddPeer(NodeRef nodeRef) {
78                 this();
79                 setNodeRef(nodeRef);
80         }
81
82         public AddPeer(String identifier, NodeRef nodeRef) {
83                 this(nodeRef);
84                 setField("Identifier", identifier);
85         }
86
87         //
88         // PRIVATE METHODS
89         //
90
91         /**
92          * Sets the noderef of the peer to add.
93          *
94          * @param nodeRef
95          *            The noderef of the peer
96          */
97         private void setNodeRef(NodeRef nodeRef) {
98                 setField("lastGoodVersion", String.valueOf(nodeRef.getLastGoodVersion()));
99                 setField("opennet", String.valueOf(nodeRef.isOpennet()));
100                 setField("identity", nodeRef.getIdentity());
101                 setField("myName", nodeRef.getMyName());
102                 setField("location", String.valueOf(nodeRef.getLocation()));
103                 setField("testnet", String.valueOf(nodeRef.isTestnet()));
104                 setField("version", String.valueOf(nodeRef.getVersion()));
105                 setField("physical.udp", nodeRef.getPhysicalUDP());
106                 setField("ark.pubURI", nodeRef.getARK().getPublicURI());
107                 setField("ark.number", String.valueOf(nodeRef.getARK().getNumber()));
108                 setField("dsaPubKey.y", nodeRef.getDSAPublicKey());
109                 setField("dsaGroup.g", nodeRef.getDSAGroup().getBase());
110                 setField("dsaGroup.p", nodeRef.getDSAGroup().getPrime());
111                 setField("dsaGroup.q", nodeRef.getDSAGroup().getSubprime());
112                 setField("auth.negTypes", FcpUtils.encodeMultiIntegerField(nodeRef.getNegotiationTypes()));
113                 setField("sig", nodeRef.getSignature());
114         }
115
116 }