source: source/ariba/utility/transport/tcpip/protlib/connectionmap.cpp@ 5344

Last change on this file since 5344 was 5284, checked in by mies, 15 years ago

+ added new transport modules and adapted ariba to them
+ exchange endpoint descriptors an link establishment
+ clean up of base communication
+ link establishment with in the presence of multiple endpoints
+ local discovery for ipv6, ipv4 and bluetooth mac addresses

File size: 4.3 KB
Line 
1/// ----------------------------------------*- mode: C++; -*--
2/// @file connectionmap.cpp
3/// stores connection related data
4/// ----------------------------------------------------------
5/// $Id: connectionmap.cpp 2872 2008-02-18 10:58:03Z bless $
6/// $HeadURL: https://svn.ipv6.tm.uka.de/nsis/protlib/trunk/src/connectionmap.cpp $
7// ===========================================================
8//
9// Copyright (C) 2005-2007, all rights reserved by
10// - Institute of Telematics, Universitaet Karlsruhe (TH)
11//
12// More information and contact:
13// https://projekte.tm.uka.de/trac/NSIS
14//
15// This program is free software; you can redistribute it and/or modify
16// it under the terms of the GNU General Public License as published by
17// the Free Software Foundation; version 2 of the License
18//
19// This program is distributed in the hope that it will be useful,
20// but WITHOUT ANY WARRANTY; without even the implied warranty of
21// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22// GNU General Public License for more details.
23//
24// You should have received a copy of the GNU General Public License along
25// with this program; if not, write to the Free Software Foundation, Inc.,
26// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27//
28// ===========================================================
29#include "connectionmap.h"
30#include "logfile.h"
31
32namespace protlib {
33 using namespace log;
34
35/** @ingroup tptcp
36 * @ingroup network
37 * @{
38 */
39
40
41/***** class ConnectionMap *****/
42
43/** @class ConnectionMap connectionmap.h
44 The class ConnectionMap saves all required information about
45 currently existing connections. Its methods allow to check for
46 connections and return, if possible, the data associated
47 with the connection.
48*/
49
50
51/** @returns true if data is not NULL, if there is not already
52 * an entry for data and if
53 * it is inserted into the internal hash maps.
54 *
55 */
56bool ConnectionMap::insert(AssocData* assoc)
57{
58 if (assoc)
59 {
60 if ( (assoc->socketfd && lookup(assoc->socketfd)) ||
61 (assoc->assoc && lookup(assoc->assoc)) ||
62 lookup(assoc->peer)) return false;
63 else
64 {
65 if (assoc->socketfd)
66 ass2data[assoc->socketfd] = assoc;
67 else
68 if (assoc->assoc)
69 ass2data[assoc->assoc] = assoc;
70 else
71 Log(ERROR_LOG,LOG_NORMAL,"ConnectionMap","insertion failed, both socketfd and associd are 0");
72
73 addr2data[assoc->peer] = assoc;
74 return true;
75 } // end if already in map
76 } else return false;
77} // end insert
78
79/** @returns a pointer to the AssocData object or NULL.
80 * @param socketfd socket file descriptor
81 */
82
83AssocData* ConnectionMap::lookup(socketfd_t socketfd) const
84{
85 const_ass2data_it_t hit= ass2data.find(socketfd);
86 if (hit!=ass2data.end()) return hit->second;
87 else return NULL;
88} // end lookup
89
90AssocData* ConnectionMap::lookup(associd_t associd) const
91{
92 const_ass2data_it_t hit= ass2data.find(associd);
93 if (hit!=ass2data.end()) return hit->second;
94 else return NULL;
95} // end lookup
96
97/** @returns a pointer to the AssocData object or NULL.
98 * @param addr IP-adress + port
99 *
100 */
101AssocData* ConnectionMap::lookup(const appladdress& addr) const
102{
103 const_addr2data_it_t hit= addr2data.find(addr);
104 if (hit!=addr2data.end()) return hit->second;
105 else return NULL;
106} // end lookup
107
108/** @returns true if the AssocData-object with socketfd
109 * could be deleted
110 * @param socketfd socket file descriptor
111 */
112bool ConnectionMap::erase(socketfd_t socketfd) {
113 bool res = true;
114 AssocData* d = lookup(socketfd);
115 if (d) {
116 if (!ass2data.erase(d->socketfd)) res = false;
117 if (!addr2data.erase(d->peer)) res = false;
118 delete d; // AssocData is deleted
119 return res;
120 } else return false;
121} // end erase
122
123/**
124 * could be deleted
125 * @param associd association id
126 * @returns true if the AssocData-object with associd
127 */
128bool ConnectionMap::erase(associd_t associd) {
129 bool res = true;
130 AssocData* d = lookup(associd);
131 if (d) {
132 if (!ass2data.erase(d->assoc)) res = false;
133 if (!addr2data.erase(d->peer)) res = false;
134 delete d; // AssocData is deleted
135 return res;
136 } else return false;
137} // end erase
138
139/*
140 *
141 */
142void ConnectionMap::clear() {
143 const_ass2data_it_t hit;
144 for (hit=ass2data.begin();hit!=ass2data.end();hit++) {
145 if (hit->second) delete hit->second;
146 } // end for hit
147 ass2data.clear();
148 addr2data.clear();
149} // end clear
150
151
152} // end namespace protlib
153/// @}
Note: See TracBrowser for help on using the repository browser.