[6043] | 1 | /*! |
---|
| 2 | * @file network_stream.h |
---|
[9300] | 3 | * implementation of a network pipe. This node handles the handshake of two network nodes and exchanges informationas |
---|
| 4 | * vial to the connection setup. |
---|
[6043] | 5 | */ |
---|
| 6 | |
---|
| 7 | #ifndef _HANDSHAKE |
---|
| 8 | #define _HANDSHAKE |
---|
| 9 | |
---|
| 10 | #include "base_object.h" |
---|
[9334] | 11 | #include "ip.h" |
---|
[6043] | 12 | #include "synchronizeable.h" |
---|
| 13 | |
---|
[9300] | 14 | //!< a struct to save the handshakes to |
---|
[9295] | 15 | struct HandshakeState |
---|
| 16 | { |
---|
| 17 | int orxId; //!< orxonox id |
---|
| 18 | int version; //!< network protocol version |
---|
[9258] | 19 | |
---|
[9295] | 20 | int networkManagerId; //!< unique id of the network manager |
---|
| 21 | int messageManagerId; //!< unique id of the message manager |
---|
| 22 | int hostId; //!< host id |
---|
| 23 | int nodeType; //!< type of the network node |
---|
[9258] | 24 | |
---|
[9295] | 25 | int completed; //!< true if completed |
---|
| 26 | int canDel; //!< true if marked for deletion |
---|
[9258] | 27 | |
---|
[9295] | 28 | int error; //!< error number |
---|
[9258] | 29 | |
---|
[9295] | 30 | std::string errorString; //!< error string |
---|
[9258] | 31 | |
---|
[9235] | 32 | //additional data |
---|
[9295] | 33 | std::string preferedNickName; //!< prefered nick name |
---|
| 34 | |
---|
[9296] | 35 | int redirectProxy; //!< true if the client should reconnect to a proxy server (either 1 or 2 ) |
---|
[9334] | 36 | IP proxy1; //!< ip address of the first proxy (0.0.0.0 of not available) |
---|
| 37 | IP proxy2; //!< ip address of the second proxy (0.0.0.0 of not available) |
---|
[6043] | 38 | }; |
---|
| 39 | |
---|
[9300] | 40 | |
---|
| 41 | //!< the handshake itself with some interface functions |
---|
[6043] | 42 | class Handshake : public Synchronizeable |
---|
| 43 | { |
---|
[9258] | 44 | |
---|
[6043] | 45 | public: |
---|
[9270] | 46 | Handshake( int nodeType, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 ); |
---|
[9258] | 47 | |
---|
| 48 | |
---|
[9259] | 49 | /* functions indicating states of the handshake */ |
---|
[9258] | 50 | /** @returns true if the handshake is completed */ |
---|
| 51 | inline bool completed(){ return localState.completed != 0 && remoteState.completed != 0; } |
---|
| 52 | /** @returns true if no error has occured until now */ |
---|
| 53 | inline bool ok(){ return localState.error == 0 && remoteState.error == 0; } |
---|
[9269] | 54 | /** stops the handshake and reject the other side with @param reason: string describing the reason */ |
---|
[9258] | 55 | inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; } |
---|
| 56 | /** @returns true if the handshake is finished and the instances can be deleted */ |
---|
| 57 | inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; } |
---|
| 58 | /** @returns true if the local state can be removed*/ |
---|
| 59 | inline bool allowDel(){ return localState.canDel == 1; } |
---|
| 60 | /** marks the handshake to be deleted */ |
---|
| 61 | inline void del(){ localState.canDel = 1; } |
---|
| 62 | |
---|
[9295] | 63 | |
---|
[9259] | 64 | /* the actual informations exchanged in the handshake */ |
---|
| 65 | /** @returns the host id of the remote host */ |
---|
| 66 | inline int getHostId(){ return remoteState.hostId; } |
---|
| 67 | /** @returns the unique id of the network game manager*/ |
---|
| 68 | inline int getNetworkGameManagerId(){ return remoteState.networkManagerId; } |
---|
| 69 | /** @returns the unique id of the message manager */ |
---|
| 70 | inline int getMessageManagerId(){ return remoteState.messageManagerId; } |
---|
[9269] | 71 | /** @returns the node type of the remote host */ |
---|
| 72 | inline int getRemoteNodeType() { return this->remoteState.nodeType; } |
---|
[9259] | 73 | |
---|
[9258] | 74 | /** sets @param nick the prefereded nick name */ |
---|
| 75 | inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; } |
---|
| 76 | /** @returns the prefered nick name */ |
---|
[9235] | 77 | inline std::string getPreferedNickName(){ return remoteState.preferedNickName; } |
---|
[9258] | 78 | |
---|
[9296] | 79 | /** @returns if true the local client should reconnect to a proxy server from the proxy server list */ |
---|
[9300] | 80 | inline bool redirect() { return this->localState.redirectProxy;} |
---|
| 81 | /** @param flag: indicating if the client should be redirected */ |
---|
| 82 | inline void setRedirect(bool flag) { this->remoteState.redirectProxy = flag; } |
---|
[9296] | 83 | |
---|
[9295] | 84 | /** @param address: the address of the proxy server 1 if any */ |
---|
[9334] | 85 | inline void setProxy1Address(IP address) { this->localState.proxy1 = address; } |
---|
[9295] | 86 | /** @returns the address of the proxy server 1 if any */ |
---|
[9334] | 87 | inline IP getProxy1Address() { return this->localState.proxy1; } |
---|
[9295] | 88 | /** @param address: the address of the proxy server 2 if any */ |
---|
[9334] | 89 | inline void setProxy2Address(IP address) { this->localState.proxy2 = address; } |
---|
[9295] | 90 | /** @returns the address of the proxy server 2 if any */ |
---|
[9334] | 91 | inline IP getProxy2Address() { return this->localState.proxy2; } |
---|
[9295] | 92 | |
---|
| 93 | |
---|
[9259] | 94 | /* variable handler function */ |
---|
[7954] | 95 | virtual void varChangeHandler( std::list<int> & id ); |
---|
[6043] | 96 | |
---|
[9259] | 97 | |
---|
[6043] | 98 | private: |
---|
[9259] | 99 | HandshakeState localState; //!< the local handshake state |
---|
| 100 | HandshakeState remoteState; //!< the remote handshake state |
---|
[9258] | 101 | |
---|
[9260] | 102 | int orxId_handler; //!< orxonox id handler |
---|
| 103 | int version_handler; //!< orxonox version id handler |
---|
[9259] | 104 | int netManId_handler; //!< network manager handler |
---|
| 105 | int msgManId_handler; //!< message manager handler |
---|
[9260] | 106 | int hostId_handler; //!< host id handler |
---|
[9268] | 107 | int nodeTypeHandler; //!< node type handler |
---|
[6043] | 108 | |
---|
[9260] | 109 | int completed_handler; //!< handshake completion handler |
---|
| 110 | int error_handler; //!< handshake error handler |
---|
| 111 | int errorString_handler; //!< handshake error string handler |
---|
| 112 | int candel_id; //!< handshake deletion handler |
---|
[9268] | 113 | int nodeType; //!, the type of the network node |
---|
[9260] | 114 | |
---|
[6043] | 115 | }; |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | #endif |
---|