forked from zeroreserve/ZeroReserve
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouter.h
More file actions
77 lines (60 loc) · 2.47 KB
/
Router.h
File metadata and controls
77 lines (60 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
This file is part of the Zero Reserve Plugin for Retroshare.
Zero Reserve is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zero Reserve is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Zero Reserve. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ROUTER_H
#define ROUTER_H
#include "zrtypes.h"
#include <map>
#include <string>
/**
* @brief Interface class for routers
*
* A route is a possible tunnel, pointing to the source of some data, for example the origin of
* an order. Each node on the network knows only the next hop of that route.
*
* A tunnel is a route that is currently in use. As it is 2-directional, each node knows the next
* hop in both direction. Tunnels exist only as long as 2 distant nodes, i.e. nodes that are not
* friends, need to communicate.
*/
class Router
{
public:
typedef std::map< ZR::VirtualAddress, std::pair< std::string, std::string > > TunnelList;
enum TunnelDirection {
SERVER = 0,
CLIENT
};
virtual void addRoute( const ZR::VirtualAddress & dest, const std::string & gateway ) = 0;
/** Query next hop of a route */
virtual const std::string nextHop( const ZR::VirtualAddress & dest ) = 0;
virtual bool hasRoute( const ZR::VirtualAddress & dest ) = 0;
/**
* adds a virtual tunnel
* @arg dest: the virtual address
* @arg gateways: a pair of the IDs of the hop forward and the hop backward
*/
virtual void addTunnel( const ZR::VirtualAddress & dest, std::pair< ZR::PeerAddress, ZR::PeerAddress > & gateways ){ m_Tunnels[ dest ] = gateways; }
virtual ZR::RetVal getTunnel( const ZR::VirtualAddress & dest, std::pair< ZR::PeerAddress, ZR::PeerAddress > & gateways )
{
TunnelList::iterator it = m_Tunnels.find( dest );
if( it == m_Tunnels.end() )
return ZR::ZR_FAILURE;
gateways = (*it).second;
return ZR::ZR_SUCCESS;
}
static Router * Instance();
protected:
TunnelList m_Tunnels;
static Router * instance;
};
#endif // ROUTER_H