KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > coldcore > coloradoftp > connection > DataPortListener


1 package com.coldcore.coloradoftp.connection;
2
3 import java.io.IOException JavaDoc;
4
5 /**
6  * Listens for incoing data connections.
7  *
8  * This class is constantly listening on a predefined port. When user is using PASV command, his/her
9  * control connection is added to the list in this class. User then initiates a data connection to
10  * the port this class listens to. When connection is accepted, this class makes sure that an incoming
11  * data connection corresponds to any of the control connections in the list (by IP address). If such
12  * control connection is found in the list the new data connection is assigned to it and the control
13  * connection is removed from the list.
14  *
15  * In order to work correctly the internal list must not contain control connections from the same host.
16  * FTP server must open several ports (about 100) to allow PASV to work correctly, so
17  * that control connections from the same host should not wait for one another.
18  *
19  * The less ports are open the more insecure FTP server gets. Malitious users can try to bing to all
20  * available data ports and if one of them has a connection with the same IP that is waiting, the file
21  * will be handed to the user (this is the case when all users are using the same gateway, every
22  * connection will then have gateway's IP address).
23  *
24  * If user tries to open a data connecion which fails for some reason then this class has to send a failed
25  * reply to the user (this will also clear the INTERRUPT state of the control connection).
26  *
27  * This class has to remove destroyed connections from the awaiting list itself. It is not allowed to
28  * operate on destroyed connections.
29  *
30  *
31  * ColoradoFTP - The Open Source FTP Server (http://cftp.coldcore.com)
32  */

33 public interface DataPortListener {
34
35   /** Set binding port
36    * @param port Port number
37    */

38   public void setPort(int port);
39
40
41   /** Get binding port
42    * @return Port number
43    */

44   public int getPort();
45
46
47   /** Bing to the port */
48   public void bind() throws IOException JavaDoc;
49
50
51   /** Unbind from the port */
52   public void unbind() throws IOException JavaDoc;
53
54
55   /** Test if connector is bound to the port.
56    * @return TRUE if it is bound, FALSE otherwise
57    */

58   public boolean isBound();
59
60
61   /** Add a connection to the list of connections which await incoming data connection from users
62    * @param connection Connection
63    * @return TRUE if connection was added to the list, FALSE if connection cannot be added (perhaps the same IP is already there)
64    */

65   public boolean addConnection(ControlConnection connection);
66
67
68   /** Remove connection from the list if it exists in it and send a failed reply to the user
69    * @param connection Connection
70    * @return TRUE if connection was removed from the list, FALSE if connection was not found
71    */

72   public boolean removeConnection(ControlConnection connection);
73 }
74
Popular Tags