close Warning: Can't use blame annotator:
No changeset 5030 in the repository

source: source/ariba/overlay/LinkDescriptor.h@ 5529

Last change on this file since 5529 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.2 KB
RevLine 
1#ifndef __LINK_DESCRIPTOR_H
2#define __LINK_DESCRIPTOR_H
3
4#include <iostream>
5#include <sstream>
6#include <ctime>
7#include <deque>
8#include <boost/foreach.hpp>
9
10#include "ariba/utility/messages.h"
11#include "ariba/utility/types.h"
12#include "ariba/CommunicationListener.h"
13
14namespace ariba {
15 class CommunicationListener;
16}
17
18using std::deque;
19using ariba::utility::Message;
20using ariba::utility::NodeID;
21using ariba::utility::SpoVNetID;
22using ariba::utility::ServiceID;
23using ariba::utility::LinkID;
24using ariba::CommunicationListener;
25
26namespace ariba {
27namespace overlay {
28
29class LinkDescriptor;
30
31std::ostream& operator<<(std::ostream& s, const LinkDescriptor* ld );
32std::ostream& operator<<(std::ostream& s, const LinkDescriptor& ld );
33
34/// LinkDescriptor
35class LinkDescriptor {
36public:
37 // ctor
38 LinkDescriptor() {
39 // default values
40 this->up = false;
41 this->dropWhenRelaysLeft = false;
42 this->fromRemote = false;
43 this->remoteNode = NodeID::UNSPECIFIED;
44 this->overlayId = LinkID::UNSPECIFIED;
45 this->communicationUp = false;
46 this->communicationId = LinkID::UNSPECIFIED;
47 this->keepAliveTime = time(NULL);
48 this->keepAliveMissed = 0;
49 this->usedAsRelay = false;
50 this->timeUsedAsRelay = time(NULL);
51 this->service = ServiceID::UNSPECIFIED;
52 this->listener = &CommunicationListener::DEFAULT;
53 this->relay = false;
54 this->localRelay = NodeID::UNSPECIFIED;
55 this->remoteRelay = NodeID::UNSPECIFIED;
56 this->remoteLinkId = LinkID::UNSPECIFIED;
57 this->autolink = false;
58 this->lastuse = time(NULL);
59 }
60
61 // dtor
62 ~LinkDescriptor() {
63 flushQueue();
64 }
65
66 // general information about the link ---------------------------------
67
68 bool up; ///< flag wheter this link is up and running
69 bool dropWhenRelaysLeft;
70 bool fromRemote; ///<flag, wheter this link was requested from remote
71
72 NodeID remoteNode; ///< remote endpoint node
73
74 LinkID overlayId; ///< the base overlay link id
75 LinkID communicationId; ///< the communication id
76 bool communicationUp; ///< flag, wheter the communication is up
77
78 time_t keepAliveTime; ///< the last time a keep-alive message was received
79 int keepAliveMissed; ///< the number of missed keep-alive messages
80
81 void markAlive() {
82 keepAliveMissed = 0;
83 keepAliveTime = time(NULL);
84 }
85
86 // relay state --------------------------------------------------------
87
88 bool usedAsRelay; ///< flag, wheter this link has been used as relay
89 time_t timeUsedAsRelay; ///< last time the link has been used as relay
90
91 void markAsRelay() {
92 usedAsRelay = true;
93 timeUsedAsRelay = time(NULL);
94 }
95
96 // owner --------------------------------------------------------------
97 ServiceID service; ///< service using this link
98 CommunicationListener* listener; ///< the listener using this node
99
100 // relay information --------------------------------------------------
101 bool relay; ///< flag whether this link is a relay link
102 NodeID localRelay; ///< the local relay node
103 NodeID remoteRelay; ///< the remote relay node
104 LinkID remoteLinkId; ///< the remote link id
105
106 // auto links ---------------------------------------------------------
107 bool autolink; ///< flag, whether this link is a auto-link
108 time_t lastuse; ///< time, when the link was last used
109 deque<Message*> messageQueue; ///< waiting messages to be delivered
110
111 /// updates the timestamp
112 void markAsUsed() {
113 lastuse = time(NULL);
114 }
115
116 /// drops waiting messsages
117 void flushQueue() {
118 BOOST_FOREACH( Message* msg, messageQueue )
119 delete msg;
120 messageQueue.clear();
121 }
122
123 std::string to_string() const {
124 std::ostringstream s;
125 s << "up=" << up << " ";
126 s << "fromRem=" << fromRemote << " ";
127 s << "remNode=" << remoteNode.toString().substr(0,6) << " ";
128 s << "serv=" << service.toString() << " ";
129 s << "overId=" << overlayId.toString().substr(0,6) << " ";
130 s << "commUp=" << communicationUp << " ";
131 s << "commId=" << communicationId.toString().substr(0,6) << " ";
132 s << "usedAsRel=" << usedAsRelay << " ";
133 s << "KeepAliveMiss=" << keepAliveMissed << " ";
134 if ( !localRelay.isUnspecified() ) {
135 s << "locRel=" << localRelay.toString().substr(0,6) << " ";
136 s << "remRel=" << remoteRelay.toString().substr(0,6) << " ";
137 s << "remLink=" << remoteLinkId.toString().substr(0,6) << " ";
138 }
139 s << "auto=" << autolink;
140 return s.str();
141 }
142};
143
144}} // namespace ariba, overlay
145
146#endif // __LINK_DESCRIPTOR_H
147
Note: See TracBrowser for help on using the repository browser.