sP2P c++ STL *nix API  1.2
NAT traversal and peer-to-peer networking API providing all utilities needed to build peer-to-peer application straigth out of box
 All Classes Functions Variables Typedefs Enumerations Enumerator
Peer.h
1 /*
2 #################################################################################################
3 # sP2P NAT Traversal/Peer-To-Peer networking API
4 #
5 # This file is part of comercial product. You can not use it in any way, redistribute it
6 # in any way and/or modify it in any way unless you get right to do so.
7 #
8 # Use licence can only be acquired from:
9 # ---------------------------------------------------
10 # AS-CAL,raziskave in razvoj, d.o.o.
11 # Kongresni trg 9, 1000 Ljubljana - Slovenia
12 # Company ID: 3913147000
13 # ---------------------------------------------------
14 # , or product legal successor.
15 #
16 #################################################################################################
17 # Ivan Milic
18 # HOLEST Engineering
19 # www.holest.com
20 # Belgrade, Serbia
21 # January, 2013
22 ##################################################################################################
23 */
24 
25 
26 
27 #ifndef _PEER_H
28 #define _PEER_H
29 
30 #include <map>
31 #include <string>
32 #include <list>
33 
34 #include "Connection.h"
35 #include "stun.h"
36 #include "Guid.h"
37 #include "IPEndPoint.h"
38 #include "Uninetwork.h"
39 
40 namespace sp2plib{
41 
43 class SP2P_API Peer{
44 public:
48  static const sp2plib::UInt32 DisconnectedState = 0;
49 
50 
54  static const sp2plib::UInt32 AuthentificatedState = 1;
55 
56 
60  Peer();
61 
62 
66  ~Peer();
67 
71  ::std::string Get(::std::string name);
72 
76  void Set(::std::string name,::std::string value);
77 
78 
97  ::std::string &operator [] (::std::string Name);
98 
103  bool RemoveProperty(::std::string Name);
104 
108  int AllPropertiesCount();
109 
113  ::std::string PropertyNameOnIndex(int Index);
114 
119 
123  sp2plib::UInt32 State;
124 
129 
134 
139 
143  bool HasNUPnP;
144 
149 
154 
159 
163  sp2plib::UInt64 LastActivityTime;
164 
168  Socket TunnelSocket;
169 
174 
178  ::std::string HostName;
179 
183  ::std::string OS;
184 
189 
195  int GetSerializationLength(bool serializeCustomProperties = true);
196 
201  unsigned char* new_GetBytes(int * len, bool serializeCustomProperties = true);
202 
210  int WriteBytes(unsigned char* buffer, int startIndex = 0, bool serializeCustomProperties = true);
211 
216  int Parse(unsigned char* Data, int startIndex = 0);
217 
218 
226  static Peer ParsePeer(unsigned char* Data, int startIndex = 0,int *len = NULL);
227 
228 
236  static Peer* new_ParsePeer(unsigned char* Data, int startIndex = 0,int *len = NULL);
237 
238 
240  void ClearValues();
241 
243  bool IsEmpty();
244 
245 
251  ::std::list<TunnelOpenMethod> NATTravMethodsUsed;
252 
259  unsigned char TunnelSecretData[32];
260 
261 private:
262 
263  //Serialization must be ordered by attribute value
264  typedef enum PeerAttributeType {
265  PAT_Unknown = 0,
266  PAT_UID = 12,
267  PAT_LocalEP = 13,
268  PAT_PublicEP = 14,
269  PAT_ApiVersion = 15,
270  PAT_NatType = 16,
271  PAT_HasNUPnP = 17,
272  PAT_CheckPointEP = 18,
273  PAT_CheckPointUID = 19,
274  PAT_State = 20,
275  PAT_HostName = 21,
276  PAT_OS = 22,
277  PAT_ApplicationUID = 23,
278  PAT_Properties = 24,
279  PAT_CanTcpAccept = 25
280  } PeerAttributeType;
281 
282  ::std::map< ::std::string,::std::string> _Properties;
283 
284 
285 
286 
287 };
288 
289 }
290 
291 #endif