Some code fixes done to multicast service classes.
[tourist.git] / App / include / Tourist / App / Application.h
bloba5887ac893a25477582a17b046a6997546116ef2
1 #ifndef APP_H_
2 #define APP_H_
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"
14 #include <vector>
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;
22 using Poco::Runnable;
23 using Poco::ThreadPool;
24 using Poco::NotificationQueue;
26 namespace Tourist {
27 namespace App {
29 class PeerConnectionWorker;
31 class Bootstrap;
33 class Bootstrapper;
35 //typedef NodeCompSetTemplate <RemoteNode, CmpOrd<Node> > NodeSet;
37 /**
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 {
47 string host;
48 int port;
49 int type; //TCP or UDP or
52 class Application : public CallbackInterface, public Runnable
54 public:
55 Application();
57 Application(Config conf);
59 ~Application();
61 int connectionTo(string host, int port, int protocol, RemoteNode **response,
62 int timeout=500);
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();
94 Config* getConfig();
96 //Should be called to initialize the Application.
97 int init();
99 void run();
101 void stopApp();
103 //Bandwidth this peer is consuming.
104 int getBwUsage();
106 private:
107 void updatePipesCache(RemoteNode &rn, AbstractPipe *pipe);
109 //Application main configuration object.
110 Config config;
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;
121 Logger &logger;
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.
138 LocalNode nodeCache;
140 CacheXfer cacheXfer;
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.
155 time_t startTime;
159 } // namespace App
160 } // namespace Tourist
162 #endif /*APP_H_*/