jSite: First commit : verion 4.0 (written by Bombe)
[jSite.git] / src / de / todesbaum / util / freenet / fcp2 / ClientHello.java
1 /*
2  * todesbaum-lib - 
3  * Copyright (C) 2006 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package de.todesbaum.util.freenet.fcp2;
21
22 import java.io.IOException;
23 import java.io.Writer;
24
25 /**
26  * Implementation of the <code>ClientHello</code> command. This command must
27  * be sent as the first command on a connection ({@link de.todesbaum.util.freenet.fcp2.Connection#connect()}
28  * takes care of that) and must not be sent afterwards.
29  * <p>
30  * The node can answer with the following messages: <code>NodeHello</code>.
31  * 
32  * @author David Roden &lt;droden@gmail.com&gt;
33  * @version $Id: ClientHello.java 356 2006-03-24 15:13:38Z bombe $
34  */
35 public class ClientHello extends Command {
36
37         /** The name of the client. */
38         protected String name;
39
40         /** The version of the FCP protocol the client expects. */
41         protected String expectedVersion = "2.0";
42
43         /**
44          * Creates a new <code>ClientHello</code> command.
45          */
46         public ClientHello() {
47                 super("ClientHello", "ClientHello-" + System.currentTimeMillis());
48         }
49
50         /**
51          * Returns the value of the <code>ExpectedVersion</code> parameter of this
52          * command. At the moment this value is not used by the node but in the
53          * future this may be used to enforce certain node versions.
54          * 
55          * @return The expected version
56          */
57         public String getExpectedVersion() {
58                 return expectedVersion;
59         }
60
61         /**
62          * Sets the value of the <code>ExpectedVersion</code> parameter of this
63          * command. At the moment this value is not used by the node but in the
64          * future this may be used to enforce certain node versions.
65          * 
66          * @param expectedVersion
67          *            The expected version
68          */
69         public void setExpectedVersion(String expectedVersion) {
70                 this.expectedVersion = expectedVersion;
71         }
72
73         /**
74          * Returns the name of the client that is connecting.
75          * 
76          * @return The name of the client
77          */
78         public String getName() {
79                 return name;
80         }
81
82         /**
83          * Sets the name of the client that is connecting.
84          * 
85          * @param name
86          *            The name of the client
87          */
88         public void setName(String name) {
89                 this.name = name;
90         }
91
92         /**
93          * {@inheritDoc}
94          */
95         @Override
96         protected void write(Writer writer) throws IOException {
97                 writer.write("Name=" + name + LINEFEED);
98                 writer.write("ExpectedVersion=" + expectedVersion + LINEFEED);
99         }
100
101 }