IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
IBR-DTNSuite
Namespaces
Classes
Files
File List
daemon
src
api
core
net
BundleReceivedEvent.cpp
BundleReceivedEvent.h
BundleReceiver.h
BundleTransfer.cpp
BundleTransfer.h
ConnectionEvent.cpp
ConnectionEvent.h
ConnectionManager.cpp
ConnectionManager.h
ConvergenceLayer.cpp
ConvergenceLayer.h
DatagramConnection.cpp
DatagramConnection.h
DatagramConvergenceLayer.cpp
DatagramConvergenceLayer.h
DatagramService.cpp
DatagramService.h
DHTNameService.cpp
DHTNameService.h
DiscoveryAgent.cpp
DiscoveryAgent.h
DiscoveryBeacon.cpp
DiscoveryBeacon.h
DiscoveryBeaconHandler.cpp
DiscoveryBeaconHandler.h
DiscoveryService.cpp
DiscoveryService.h
EMailConvergenceLayer.cpp
EMailConvergenceLayer.h
EMailImapService.cpp
EMailImapService.h
EMailSmtpService.cpp
EMailSmtpService.h
FileConvergenceLayer.cpp
FileConvergenceLayer.h
FileMonitor.cpp
FileMonitor.h
HTTPConvergenceLayer.cpp
HTTPConvergenceLayer.h
IPNDAgent.cpp
IPNDAgent.h
LOWPANConnection.cpp
LOWPANConnection.h
LOWPANConvergenceLayer.cpp
LOWPANConvergenceLayer.h
LOWPANDatagramService.cpp
LOWPANDatagramService.h
NativeP2pManager.cpp
NativeP2pManager.h
P2PDialupEvent.cpp
P2PDialupEvent.h
P2PDialupExtension.cpp
P2PDialupExtension.h
TCPConnection.cpp
TCPConnection.h
TCPConvergenceLayer.cpp
TCPConvergenceLayer.h
TransferAbortedEvent.cpp
TransferAbortedEvent.h
TransferCompletedEvent.cpp
TransferCompletedEvent.h
UDPConvergenceLayer.cpp
UDPConvergenceLayer.h
UDPDatagramService.cpp
UDPDatagramService.h
WifiP2PManager.cpp
WifiP2PManager.h
routing
security
storage
CapsuleWorker.cpp
CapsuleWorker.h
Component.cpp
Component.h
config.h
Configuration.cpp
Configuration.h
Debugger.cpp
Debugger.h
DevNull.cpp
DevNull.h
DTNTPWorker.cpp
DTNTPWorker.h
EchoWorker.cpp
EchoWorker.h
Main.cpp
NativeDaemon.cpp
NativeDaemon.h
NTService.cpp
ibrcommon
ibrdtn
tools
File Members
TCPConnection.h
Go to the documentation of this file.
1
/*
2
* TCPConnection.h
3
*
4
* Copyright (C) 2011 IBR, TU Braunschweig
5
*
6
* Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7
*
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
11
*
12
* http://www.apache.org/licenses/LICENSE-2.0
13
*
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
19
*
20
*/
21
22
#ifndef TCPCONNECTION_H_
23
#define TCPCONNECTION_H_
24
25
#include "
core/NodeEvent.h
"
26
27
#include <
ibrdtn/data/Bundle.h
>
28
#include <
ibrdtn/data/EID.h
>
29
#include <
ibrdtn/data/MetaBundle.h
>
30
#include <
ibrdtn/data/Serializer.h
>
31
32
#include <
ibrdtn/streams/StreamConnection.h
>
33
#include <
ibrdtn/streams/StreamContactHeader.h
>
34
35
#include <
ibrcommon/net/socket.h
>
36
#include <
ibrcommon/net/socketstream.h
>
37
#include <
ibrcommon/thread/Queue.h
>
38
#include <
ibrcommon/thread/SharedReference.h
>
39
40
#include <memory>
41
42
namespace
dtn
43
{
44
namespace
net
45
{
46
class
TCPConvergenceLayer;
47
48
class
TCPConnection
:
public
dtn::streams::StreamConnection::Callback
,
public
ibrcommon::DetachedThread
49
{
50
const
static
std::string TAG;
51
public
:
60
TCPConnection
(
TCPConvergenceLayer
&tcpsrv,
const
dtn::core::Node
&node,
ibrcommon::clientsocket
*sock,
const
size_t
timeout = 10);
61
66
virtual
~TCPConnection
();
67
71
virtual
void
initialize
()
throw
();
72
76
void
shutdown
()
throw
();
77
82
const
dtn::streams::StreamContactHeader
&
getHeader
()
const
;
83
88
const
dtn::core::Node
&
getNode
()
const
;
89
93
virtual
void
eventShutdown
(
dtn::streams::StreamConnection::ConnectionShutdownCases
csc)
throw
();
94
virtual
void
eventTimeout
()
throw
();
95
virtual
void
eventError
()
throw
();
96
virtual
void
eventConnectionUp
(
const
dtn::streams::StreamContactHeader
&header)
throw
();
97
virtual
void
eventConnectionDown
()
throw
();
98
99
virtual
void
eventBundleRefused
()
throw
();
100
virtual
void
eventBundleForwarded
()
throw
();
101
virtual
void
eventBundleAck
(
const
dtn::data::Length
&ack)
throw
();
102
103
virtual
void
addTrafficIn
(
size_t
)
throw
();
104
virtual
void
addTrafficOut
(
size_t
)
throw
();
105
106
dtn::core::Node::Protocol
getDiscoveryProtocol
()
const
;
107
112
void
queue
(
const
dtn::net::BundleTransfer
&job);
113
114
bool
match
(
const
dtn::core::Node
&n)
const
;
115
bool
match
(
const
dtn::data::EID
&destination)
const
;
116
bool
match
(
const
dtn::core::NodeEvent
&evt)
const
;
117
118
#ifdef WITH_TLS
119
122
void
enableTLS();
123
#endif
124
125
protected
:
126
void
rejectTransmission
();
127
128
void
setup
()
throw
();
129
void
connect
();
130
void
run
()
throw
();
131
void
finally
()
throw
();
132
void
__cancellation
()
throw
();
133
134
void
clearQueue
();
135
136
void
keepalive
();
137
bool
good
()
const
;
138
139
void
initiateExtendedHandshake
()
throw
(
ibrcommon::Exception
);
140
141
private
:
142
class
KeepaliveSender :
public
ibrcommon::JoinableThread
143
{
144
public
:
145
KeepaliveSender(
TCPConnection
&connection,
size_t
&keepalive_timeout);
146
~KeepaliveSender();
147
151
void
run
()
throw
();
152
156
void
__cancellation
()
throw
();
157
158
private
:
159
ibrcommon::Conditional
_wait;
160
TCPConnection
&_connection;
161
size_t
&_keepalive_timeout;
162
};
163
164
class
Sender :
public
ibrcommon::JoinableThread
,
public
ibrcommon::Queue
<dtn::net::BundleTransfer>
165
{
166
public
:
167
Sender(
TCPConnection
&connection);
168
virtual
~Sender();
169
170
protected
:
171
void
run
()
throw
();
172
void
finally
()
throw
();
173
void
__cancellation
()
throw
();
174
175
private
:
176
TCPConnection
&_connection;
177
};
178
179
void
__setup_socket(
ibrcommon::clientsocket
*sock,
bool
server);
180
181
// lock object for the procotol stream
182
typedef
ibrcommon::SharedReference<dtn::streams::StreamConnection>
safe_streamconnection
;
183
188
safe_streamconnection
getProtocolStream()
throw
(
ibrcommon::Exception
);
189
190
dtn::streams::StreamContactHeader
_peer;
191
dtn::core::Node
_node;
192
193
ibrcommon::clientsocket
*_socket;
194
195
ibrcommon::socketstream
*_socket_stream;
196
197
// optional security layer between socketstream and bundle protocol layer
198
std::iostream *_sec_stream;
199
200
// mutex for the protocol stream
201
ibrcommon::RWMutex
_protocol_stream_mutex;
202
203
// this connection stream implements the bundle protocol
204
dtn::streams::StreamConnection
*_protocol_stream;
205
206
// This thread gets awaiting bundles of the queue
207
// and transmit them to the peer.
208
Sender _sender;
209
210
// Keepalive sender
211
KeepaliveSender _keepalive_sender;
212
213
// handshake variables
214
size_t
_timeout;
215
216
ibrcommon::Queue<dtn::net::BundleTransfer>
_sentqueue;
217
dtn::data::Length
_lastack;
218
dtn::data::Length
_resume_offset;
219
size_t
_keepalive_timeout;
220
221
TCPConvergenceLayer
&_callback;
222
223
/* flags to be used in this nodes StreamContactHeader */
224
dtn::data::Bitset<dtn::streams::StreamContactHeader::HEADER_BITS>
_flags;
225
226
/* with this boolean the connection is marked as aborted */
227
bool
_aborted;
228
};
229
}
230
}
231
232
#endif
/* TCPCONNECTION_H_ */
daemon
src
net
TCPConnection.h
Generated on Thu Mar 27 2014 09:26:20 for IBR-DTNSuite by
1.8.4