4 #include "Tourist/Message/RemoteNode.h"
5 #include "Tourist/Message/MessageDispatcher.h"
6 #include "Tourist/Message/MessageTypeData.h"
7 #include "Tourist/Net/TransportFactory.h"
8 #include "Tourist/LocalNode.h"
9 #include "Tourist/Util/Config.h"
10 #include "Tourist/App/CacheXfer.h"
11 #include "Poco/Runnable.h"
12 #include "Poco/NotificationQueue.h"
13 #include "Poco/ThreadPool.h"
16 using Tourist::Message::RemoteNode
;
17 using Tourist::Message::MessageDispatcher
;
18 using Tourist::Message::MessageTypeData
;
19 using Tourist::Net::TransportFactory
;
20 using Tourist::Util::Config
;
23 using Poco::ThreadPool
;
24 using Poco::NotificationQueue
;
29 class PeerConnectionWorker
;
35 //typedef NodeCompSetTemplate <RemoteNode, CmpOrd<Node> > NodeSet;
38 * Main entry point into the application. Starts by reading configuration
39 * file, fire up the underlying transport and handles connection requests from
40 * the transport factory. The logic for handling request is done through remote-node
43 //TODO The current callback interface don't use any specialized structure for notifying
44 // connection notification. This makes it impossible to use along with the pipe notifications.
46 struct TransportInfo
{
49 int type
; //TCP or UDP or
52 class Application
: public CallbackInterface
, public Runnable
57 Application(Config conf
);
61 int connectionTo(string host
, int port
, int protocol
, RemoteNode
**response
,
64 int getRemoteCache(RemoteNode
* contactNode
, int cacheType
, int startLevel
, int endLevel
,
65 int timeout
, Tourist::NodeSet
&result
);
67 bool searchRemoteLinks(Node
& recipient
, NodeSet
& result
,
68 unsigned int flags
=HIGHER_LEVELS
|EQUAL_LEVELS
|LOWER_LEVELS
|
69 FIND_SUFFIXES
|FIND_PREFIXES
|ONE_LEVEL_LOWER
);
71 Node
* getNextHop(NodeSet
&audienceSet
, Node
*source
, int step
, int type
);
73 void setLevel(int newLevel
);
76 //Interface (CallbackInterface) method for connection call back
77 void callback(void *pipe
);
79 void addNewNode(RemoteNode
*node
);
81 int getNodeCount(int level
, unsigned int flags
=PREFIX
|SUFFIX
);
83 bool getTopNode(Node
&query
, Node
**result
, int type
);
85 bool getForwardingNode(Node
& query
, Node
**result
, int type
);
87 bool getConnection(RemoteNode query
, RemoteNode
**rConnection
);
89 void getLocalNodeInfo(RemoteNode
&rn
);
91 //Returns structure of type transport for all currently available transports.
92 vector
<TransportInfo
> getEnabledTransports();
96 //Should be called to initialize the Application.
103 //Bandwidth this peer is consuming.
107 void updatePipesCache(RemoteNode
&rn
, AbstractPipe
*pipe
);
109 //Application main configuration object.
112 //main system bus for message exchange.
113 MessageDispatcher messageBus
;
115 //handles the message types
116 MessageTypeData messageTypeData
;
118 //cache for remote pipes
119 map
<RemoteNode
, AbstractPipe
*> networkPipes
;
123 //We need to keep reference to those nodes who haven't join our network
124 //or we waiting to receive more information about them.
125 Tourist::NodeSet nodesInTransaction
;
127 TransportFactory transport
;
129 bool shouldBeRunning
;
131 //handle peer handshake requests/responses.
132 vector
< AutoPtr
<PeerConnectionWorker
> > workers
;
134 ThreadPool threadPool
;
136 //All tourist related manipulation (routes, nodes etc)
137 //will be handled by this cache object.
142 NotificationQueue queue
;
144 Poco::Thread cacheRun
;
146 Poco::Thread bootRun
;
148 Bootstrap
*bootstrap
;
150 Bootstrapper
*bootstrapper
;
152 //time when this application was initiated
153 //This will be used for measuring bandwidth
154 //usage by this peer.
160 } // namespace Tourist