1 #ifndef PEERCONNECTIONWORKER_H
2 #define PEERCONNECTIONWORKER_H
5 #include "Tourist/AbstractPipe.h"
6 #include "Tourist/Message/MessageProcessor.h"
7 #include "Tourist/Message/RemoteNode.h"
8 #include "Tourist/Util/CallbackInterface.h"
9 #include "Poco/Runnable.h"
10 #include "Poco/Thread.h"
11 #include "Poco/Logger.h"
12 #include "Poco/Mutex.h"
13 #include "Poco/NotificationQueue.h"
15 using Tourist::Message::MessageProcessor
;
16 using Tourist::Message::RemoteNode
;
17 using Tourist::AbstractPipe
;
21 using Poco::FastMutex
;
22 using Poco::NotificationQueue
;
36 * Handle peer handshake in a new thread. Part of thread pool
37 * in Application class.
40 class PeerConnectionWorker
: public Tourist::Util::CallbackInterface
,
45 PeerConnectionWorker (Application
*app
, AbstractPipe
*pipe
, RemoteNode
&response
,
46 bool isActive
, int timeout
=5);
49 ~PeerConnectionWorker();
57 //called upon the recept of MsgPeerAnnouncement message.
58 void handleHandshake();
60 //un-register pipe connect/disconnect handler
63 Tourist::Message::RemoteNode
* getResult();
67 void callback(void *);
77 void handleHandshake(AbstractMessage
*message
);
79 int sendResponse(bool isAck
);
81 Tourist::Message::MessageProcessor messageProcessor
;
83 Tourist::Message::MessageTypeData msgTypeData
;
87 //true value indicates that we are initiating peer handshake
93 //Set if we successfuly resolved the peer info
96 //peer connection should be resolved before this timeout value.
99 //Information of the connected node.
100 Tourist::Message::RemoteNode
*result
;
104 static FastMutex mutex
;
106 //The node that should be sent as a response in a handshake.
111 NotificationQueue queue
;
113 //for reference counting purpose.
116 static int ref_count
;
118 }; //class PeerConnectionWorker
120 } //namespace Application
121 } //namespace Tourist
123 #endif /*PEERCONNECTIONWORKER_H*/