forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
Substrate.h
Go to the documentation of this file.
1 
9 #ifndef SUBSTRATE_H
10 #define SUBSTRATE_H
11 
12 #include "Forest.h"
13 #include "Packet.h"
14 #include "PacketStoreTs.h"
15 #include "Queue.h"
16 #include "IdMap.h"
17 #include "UiSetPair.h"
18 #include "Logger.h"
19 #include <pthread.h>
20 #include <string>
21 
22 namespace forest {
23 
29 class Substrate {
30 public:
31  Substrate(fAdr_t, ipa_t, fAdr_t, ipa_t, ipp_t, uint64_t, int,
32  void* (*)(void*), int, int, PacketStoreTs*, Logger*);
33  ~Substrate();
34 
35  bool init();
36  bool run(int);
37 
38  void setRtrPort(ipp_t);
39  void setNonce(uint64_t);
40  void setRtrReady(bool);
41 
42  struct QueuePair {
43  Queue in; Queue out;
44  };
45 private:
47  ipa_t myIp;
49  ipa_t rtrIp;
50  ipp_t rtrPort;
51  uint64_t nonce;
52  bool rtrReady;
53 
54  uint64_t seqNum;
55  uint64_t now;
56 
58  struct ThreadInfo {
59  pthread_t thid;
60  QueuePair qp;
61  uint64_t seqNum;
62  uint64_t ts;
63  };
64 
65  int dgSock;
66  int dgPort;
67  int listenSock;
68  int listenPort;
69 
73  UiSetPair *threads;
74  void* (*handler)(void*);
75  IdMap *inReqMap;
76  IdMap *outReqMap;
78 
80  // internal helper methods
81  void inbound(pktx);
82  void outbound(pktx,int);
83  void sendToForest(int);
84  int recvFromForest();
85  bool connect();
86  bool disconnect();
87 };
88 
89 inline void Substrate::setRtrPort(ipp_t port) { rtrPort = port; }
90 inline void Substrate::setNonce(uint64_t nonce1) { nonce = nonce1; }
91 inline void Substrate::setRtrReady(bool ready) { rtrReady = ready; }
92 
93 } // ends namespace
94 
95 #endif