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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#include "connectionhandler.h"
#include <stdio.h>
#include "hugin.hpp"
ConnectionHandler connection_handler;
ConnectionHandler::ConnectionHandler()
{
}
void ConnectionHandler::init(clientid_t clientid)
{
DEBUG(conn, "Adding client %p to connection list\n", clientid);
connlist[clientid] = std::set<nodeid_t>();
DEBUG(conn, "Connections (%d):\n", (int)connlist.size());
ConnectionList::iterator it;
for(it = connlist.begin(); it != connlist.end(); it++)
{
DEBUG(conn, "\t%p\n", it->first);
}
}
void ConnectionHandler::close(clientid_t clientid)
{
connlist.erase(clientid);
DEBUG(conn, "Removed connection\n");
}
void ConnectionHandler::login(clientid_t clientid, std::string user, std::string password)
{
authlist[clientid] = (password == "hundemad");
DEBUG(conn, "Authentication %d\n", authlist[clientid]);
}
void ConnectionHandler::logout(clientid_t clientid)
{
authlist[clientid] = false;
DEBUG(conn, "Authentication %d\n", authlist[clientid]);
}
bool ConnectionHandler::authenticated(clientid_t clientid)
{
return authlist.find(clientid) != authlist.end() && authlist[clientid];
}
void ConnectionHandler::subscribe(clientid_t clientid, nodeid_t nodeid)
{
connlist[clientid].insert(nodeid);
DEBUG(conn, "Added subscriber of %d\n", (int)nodeid);
}
void ConnectionHandler::unsubscribe(clientid_t clientid, nodeid_t nodeid)
{
connlist[clientid].erase(nodeid);
}
SubscriberList ConnectionHandler::subscriberlist(NodeIdList nodes)
{
DEBUG(conn, "Subscriberlist request (#nodes: %d)\n", (int)nodes.size());
SubscriberList clients;
for(NodeIdList::iterator i = nodes.begin(); i != nodes.end(); i++)
{
nodeid_t tid = *i;
DEBUG(conn, "Locating subscribers of node %d\n", (int)tid);
for(ConnectionList::iterator ci = connlist.begin();
ci != connlist.end(); ci++)
{
std::set<nodeid_t>::iterator ti = ci->second.find(tid);
if(ti != ci->second.end())
{
std::pair<clientid_t, nodeid_t> m;
m.first = ci->first;
m.second = tid;
clients.push_back(m);
}
}
}
return clients;
}
|