IBR-DTN  1.0.0
NodeHandshakeExtension.h
Go to the documentation of this file.
1 /*
2  * NodeHandshakeExtension.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 NODEHANDSHAKEEXTENSION_H_
23 #define NODEHANDSHAKEEXTENSION_H_
24 
26 #include "core/AbstractWorker.h"
27 #include "core/EventReceiver.h"
28 #include "core/NodeEvent.h"
29 
30 #include <ibrcommon/thread/Mutex.h>
31 #include <ibrcommon/thread/Queue.h>
32 #include <map>
33 
34 namespace dtn
35 {
36  namespace routing
37  {
38  class NodeHandshakeExtension : public RoutingExtension, public dtn::core::EventReceiver<dtn::core::NodeEvent>
39  {
40  static const std::string TAG;
41 
42  public:
44  virtual ~NodeHandshakeExtension();
45 
46  void raiseEvent(const dtn::core::NodeEvent &evt) throw ();
47  void componentUp() throw ();
48  void componentDown() throw ();
49 
50  void doHandshake(const dtn::data::EID &eid);
51 
53 
57  void requestHandshake(const dtn::data::EID &destination, NodeHandshake &request) const;
58 
62  void responseHandshake(const dtn::data::EID &source, const NodeHandshake &request, NodeHandshake &answer);
63 
67  void processHandshake(const dtn::data::EID &source, NodeHandshake &answer);
68 
69  protected:
70  void processHandshake(const dtn::data::Bundle &bundle);
71 
72  private:
73  class HandshakeEndpoint : public dtn::core::AbstractWorker
74  {
75  public:
76  HandshakeEndpoint(NodeHandshakeExtension &callback);
77  virtual ~HandshakeEndpoint();
78 
79  void callbackBundleReceived(const Bundle &b);
80  void query(const dtn::data::EID &eid);
81  void push(const NodeHandshakeItem::IDENTIFIER id);
82 
83  void send(dtn::data::Bundle &b);
84 
85  void removeFromBlacklist(const dtn::data::EID &eid);
86 
87  private:
88  NodeHandshakeExtension &_callback;
89  std::map<dtn::data::EID, dtn::data::Timestamp> _blacklist;
90  ibrcommon::Mutex _blacklist_lock;
91  };
92 
96  HandshakeEndpoint _endpoint;
97 
98  static const dtn::data::EID BROADCAST_ENDPOINT;
99  };
100  } /* namespace routing */
101 } /* namespace dtn */
102 #endif /* NODEHANDSHAKEEXTENSION_H_ */
void requestHandshake(const dtn::data::EID &destination, NodeHandshake &request) const
void pushHandshakeUpdated(const NodeHandshakeItem::IDENTIFIER id)
void responseHandshake(const dtn::data::EID &source, const NodeHandshake &request, NodeHandshake &answer)
void doHandshake(const dtn::data::EID &eid)
void raiseEvent(const dtn::core::NodeEvent &evt)
void processHandshake(const dtn::data::EID &source, NodeHandshake &answer)