4 * The secure anycast tunneling protocol (satp) defines a protocol used
5 * for communication between any combination of unicast and anycast
6 * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
7 * mode and allows tunneling of every ETHER TYPE protocol (e.g.
8 * ethernet, ip, arp ...). satp directly includes cryptography and
9 * message authentication based on the methodes used by SRTP. It is
10 * intended to deliver a generic, scaleable and secure solution for
11 * tunneling and relaying of packets of any protocol.
14 * Copyright (C) 2007-2008 Othmar Gsenger, Erwin Nindl,
15 * Christian Pointner <satp@wirdorange.org>
17 * This file is part of Anytun.
19 * Anytun is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 3 as
21 * published by the Free Software Foundation.
23 * Anytun is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with anytun. If not, see <http://www.gnu.org/licenses/>.
32 #include "threadUtils.hpp"
33 #include "datatypes.h"
34 #include "keyDerivationFactory.h"
37 #include "connectionList.h"
39 ConnectionList
* ConnectionList::inst
= NULL
;
40 Mutex
ConnectionList::instMutex
;
41 ConnectionList
& gConnectionList
= ConnectionList::instance();
44 ConnectionList
& ConnectionList::instance()
47 static instanceCleaner c
;
49 inst
= new ConnectionList();
54 ConnectionList::ConnectionList()
58 ConnectionList::~ConnectionList()
61 ConnectionMap::iterator it;
62 for(it = connections_.begin(); it != connections_.end(); ++it)
64 //delete &it->second.kd_;
69 void ConnectionList::addConnection(ConnectionParam
&conn
, u_int16_t mux
)
73 std::pair
<ConnectionMap::iterator
, bool> ret
= connections_
.insert(ConnectionMap::value_type(mux
, conn
));
76 connections_
.erase(ret
.first
);
77 connections_
.insert(ConnectionMap::value_type(mux
, conn
));
81 const ConnectionMap::iterator
ConnectionList::getEnd()
83 return connections_
.end();
86 ConnectionMap::iterator
ConnectionList::getBeginUnlocked()
88 return connections_
.begin();
91 ConnectionMap::iterator
ConnectionList::getEndUnlocked()
93 return connections_
.end();
96 const ConnectionMap::iterator
ConnectionList::getConnection(u_int16_t mux
)
99 ConnectionMap::iterator it
= connections_
.find(mux
);
104 ConnectionParam
& ConnectionList::getOrNewConnectionUnlocked(u_int16_t mux
)
106 ConnectionMap::iterator it
= connections_
.find(mux
);
107 if(it
!=connections_
.end())
111 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
112 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'
116 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
117 'i', 'j', 'k', 'l', 'm', 'n'
120 SeqWindow
* seq
= new SeqWindow(0);
122 KeyDerivation
* kd
= KeyDerivationFactory::create(gOpt
.getKdPrf());
123 kd
->init(Buffer(key
, sizeof(key
)), Buffer(salt
, sizeof(salt
)));
124 ConnectionParam
conn ( (*kd
), (*seq
), seq_nr_
, "", 0);
125 connections_
.insert(ConnectionMap::value_type(mux
, conn
));
126 it
= connections_
.find(mux
);
130 void ConnectionList::clear()
133 connections_
.clear();
136 bool ConnectionList::empty()
139 return connections_
.empty();
142 Mutex
& ConnectionList::getMutex()