added manpage source
[anytun.git] / connectionList.cpp
blob3c86d71f32ff0d8a0f7dce02eab9db2fa0233d44
1 /*
2 * anytun
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 anytun.org <satp@wirdorange.org>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2
18 * as published by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program (see the file COPYING included with this
27 * distribution); if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "threadUtils.hpp"
32 #include "datatypes.h"
33 #include "keyDerivationFactory.h"
34 #include "options.h"
36 #include "connectionList.h"
38 ConnectionList::ConnectionList()
42 ConnectionList::~ConnectionList()
44 /* Lock lock(mutex_);
45 ConnectionMap::iterator it;
46 for(it = connections_.begin(); it != connections_.end(); ++it)
48 //delete &it->second.kd_;
53 void ConnectionList::addConnection(ConnectionParam &conn, u_int16_t mux )
55 Lock lock(mutex_);
57 std::pair<ConnectionMap::iterator, bool> ret = connections_.insert(ConnectionMap::value_type(mux, conn));
58 if(!ret.second)
60 connections_.erase(ret.first);
61 connections_.insert(ConnectionMap::value_type(mux, conn));
65 const ConnectionMap::iterator ConnectionList::getEnd()
67 return connections_.end();
70 ConnectionMap::iterator ConnectionList::getBeginUnlocked()
72 return connections_.begin();
75 ConnectionMap::iterator ConnectionList::getEndUnlocked()
77 return connections_.end();
80 const ConnectionMap::iterator ConnectionList::getConnection(u_int16_t mux)
82 Lock lock(mutex_);
83 ConnectionMap::iterator it = connections_.find(mux);
84 return it;
88 ConnectionParam & ConnectionList::getOrNewConnectionUnlocked(u_int16_t mux)
90 ConnectionMap::iterator it = connections_.find(mux);
91 if(it!=connections_.end())
92 return it->second;
94 uint8_t key[] = {
95 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
96 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'
99 uint8_t salt[] = {
100 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
101 'i', 'j', 'k', 'l', 'm', 'n'
104 SeqWindow * seq= new SeqWindow(0);
105 seq_nr_t seq_nr_=0;
106 KeyDerivation * kd = KeyDerivationFactory::create(gOpt.getKdPrf());
107 kd->init(Buffer(key, sizeof(key)), Buffer(salt, sizeof(salt)));
108 ConnectionParam conn ( (*kd), (*seq), seq_nr_, "", 0);
109 connections_.insert(ConnectionMap::value_type(mux, conn));
110 it = connections_.find(mux);
111 return it->second;
114 void ConnectionList::clear()
116 Lock lock(mutex_);
117 connections_.clear();
120 bool ConnectionList::empty()
122 Lock lock(mutex_);
123 return connections_.empty();
126 Mutex& ConnectionList::getMutex()
128 return mutex_;