📄 Update year in copyright line
[jSite.git] / src / main / java / de / todesbaum / util / freenet / fcp2 / ClientHello.java
1 /*
2  * jSite - ClientHello.java - Copyright Â© 2006–2019 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 de.todesbaum.util.freenet.fcp2;
20
21 import java.io.IOException;
22 import java.io.Writer;
23
24 /**
25  * Implementation of the <code>ClientHello</code> command. This command must
26  * be sent as the first command on a connection ({@link de.todesbaum.util.freenet.fcp2.Connection#connect()}
27  * takes care of that) and must not be sent afterwards.
28  * <p>
29  * The node can answer with the following messages: <code>NodeHello</code>.
30  *
31  * @author David Roden &lt;droden@gmail.com&gt;
32  * @version $Id$
33  */
34 public class ClientHello extends Command {
35
36         /** The name of the client. */
37         protected String name;
38
39         /** The version of the FCP protocol the client expects. */
40         protected String expectedVersion = "2.0";
41
42         /**
43          * Creates a new <code>ClientHello</code> command.
44          */
45         public ClientHello() {
46                 super("ClientHello", "ClientHello-" + System.currentTimeMillis());
47         }
48
49         /**
50          * Returns the value of the <code>ExpectedVersion</code> parameter of this
51          * command. At the moment this value is not used by the node but in the
52          * future this may be used to enforce certain node versions.
53          *
54          * @return The expected version
55          */
56         public String getExpectedVersion() {
57                 return expectedVersion;
58         }
59
60         /**
61          * Sets the value of the <code>ExpectedVersion</code> parameter of this
62          * command. At the moment this value is not used by the node but in the
63          * future this may be used to enforce certain node versions.
64          *
65          * @param expectedVersion
66          *            The expected version
67          */
68         public void setExpectedVersion(String expectedVersion) {
69                 this.expectedVersion = expectedVersion;
70         }
71
72         /**
73          * Returns the name of the client that is connecting.
74          *
75          * @return The name of the client
76          */
77         public String getName() {
78                 return name;
79         }
80
81         /**
82          * Sets the name of the client that is connecting.
83          *
84          * @param name
85          *            The name of the client
86          */
87         public void setName(String name) {
88                 this.name = name;
89         }
90
91         /**
92          * {@inheritDoc}
93          */
94         @Override
95         protected void write(Writer writer) throws IOException {
96                 writer.write("Name=" + name + LINEFEED);
97                 writer.write("ExpectedVersion=" + expectedVersion + LINEFEED);
98         }
99
100 }