bugfix@ sender and receiver reset packet size at begin of loop
[anytun.git] / connectionList.cpp
blob93a23b9810fc87f1330b02696f1d207b6ef391a0
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"
34 #include "connectionList.h"
36 ConnectionList::ConnectionList()
40 ConnectionList::~ConnectionList()
42 /* Lock lock(mutex_);
43 ConnectionMap::iterator it;
44 for(it = connections_.begin(); it != connections_.end(); ++it)
46 //delete &it->second.kd_;
51 void ConnectionList::addConnection(ConnectionParam &conn, u_int16_t mux )
53 Lock lock(mutex_);
55 std::pair<ConnectionMap::iterator, bool> ret = connections_.insert(ConnectionMap::value_type(mux, conn));
56 if(!ret.second)
58 connections_.erase(ret.first);
59 connections_.insert(ConnectionMap::value_type(mux, conn));
63 const ConnectionMap::iterator ConnectionList::getEnd()
65 return connections_.end();
68 const ConnectionMap::iterator ConnectionList::getConnection(u_int16_t mux)
70 Lock lock(mutex_);
71 ConnectionMap::iterator it = connections_.find(mux);
72 return it;
76 ConnectionParam & ConnectionList::getOrNewConnectionUnlocked(u_int16_t mux)
78 ConnectionMap::iterator it = connections_.find(mux);
79 if(it!=connections_.end())
80 return it->second;
82 uint8_t key[] = {
83 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
84 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'
87 uint8_t salt[] = {
88 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
89 'i', 'j', 'k', 'l', 'm', 'n'
92 SeqWindow * seq= new SeqWindow(0);
93 seq_nr_t seq_nr_=0;
94 KeyDerivation * kd = new KeyDerivation;
95 kd->init(Buffer(key, sizeof(key)), Buffer(salt, sizeof(salt)));
96 ConnectionParam conn ( (*kd), (*seq), seq_nr_, "", 0);
97 connections_.insert(ConnectionMap::value_type(mux, conn));
98 it = connections_.find(mux);
99 return it->second;
102 void ConnectionList::clear()
104 Lock lock(mutex_);
105 connections_.clear();
108 bool ConnectionList::empty()
110 Lock lock(mutex_);
111 return connections_.empty();
114 Mutex& ConnectionList::getMutex()
116 return mutex_;