- Timestamp:
- Jul 29, 2009, 10:25:32 AM (15 years ago)
- Location:
- source/ariba
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/communication/BaseCommunication.cpp
r5284 r5406 84 84 85 85 logging_info( "Searching for local locators ..." ); 86 discover Endpoints(localDescriptor.getEndpoints());86 discover_endpoints(localDescriptor.getEndpoints()); 87 87 logging_info( "Done. Local endpoints = " << localDescriptor.toString() ); 88 88 -
source/ariba/communication/EndpointDescriptor.h
r5284 r5406 111 111 bool operator==(const EndpointDescriptor& rh) const { 112 112 if (rh.isUnspecified() && isUnspecified()) return true; 113 return false;113 return endpoints == rh.endpoints; 114 114 } 115 115 116 116 bool operator!=(const EndpointDescriptor& rh) const { 117 117 if (!rh.isUnspecified() && !isUnspecified()) return true; 118 return false;118 return endpoints != rh.endpoints; 119 119 } 120 120 -
source/ariba/communication/networkinfo/AddressDiscovery.hpp
r5284 r5406 6 6 #include <sys/types.h> 7 7 #include <sys/socket.h> 8 #include <sys/ioctl.h> 9 #include <sys/socket.h> 10 8 11 #include <arpa/inet.h> 12 9 13 #include <netinet/in.h> 14 10 15 #include <net/if.h> 16 11 17 #include <ifaddrs.h> 18 19 #include <bluetooth/bluetooth.h> 20 #include <bluetooth/hci.h> 21 #include <bluetooth/hci_lib.h> 12 22 13 23 using namespace ariba::addressing; … … 26 36 } 27 37 28 void discoverEndpoints( endpoint_set& endpoints ) { 38 39 int dev_info(int s, int dev_id, long arg) { 40 endpoint_set* set = (endpoint_set*)arg; 41 struct hci_dev_info di; 42 di.dev_id = dev_id; 43 if (ioctl(s, HCIGETDEVINFO, (void *) &di)) return 0; 44 mac_address mac; 45 mac.bluetooth( di.bdaddr ); 46 address_vf vf = mac; 47 set->add(vf); 48 return 0; 49 } 50 51 void discover_bluetooth( endpoint_set& endpoints ) { 52 hci_for_each_dev(HCI_UP, &dev_info, (long)&endpoints ); 53 } 54 55 void discover_ip_addresses( endpoint_set& endpoints ) { 29 56 struct ifaddrs* ifaceBuffer = NULL; 30 57 struct ifaddrs* tmpAddr = NULL; … … 63 90 mac_address mac = getMacFromIF(i->ifa_name); 64 91 address_vf vf = mac; 65 endpoints.add( vf );92 // endpoints.add( vf ); 66 93 } 67 94 } 68 95 } 69 96 97 void discover_endpoints( endpoint_set& endpoints ) { 98 discover_ip_addresses( endpoints ); 99 discover_bluetooth( endpoints ); 100 } 101 70 102 #endif /* ADDRESSDISCOVERY_HPP_ */ -
source/ariba/overlay/BaseOverlay.cpp
r5316 r5406 146 146 } 147 147 148 /// forwards a message over relays/ overlay/directly using link descriptor148 /// forwards a message over relays/directly using link descriptor 149 149 seqnum_t BaseOverlay::sendMessage( Message* message, const LinkDescriptor* ld ) { 150 150 151 151 // directly send message 152 152 if ( !ld->communicationId.isUnspecified() && ld->communicationUp ) { 153 logging_debug(" sendMessage: Sending message via Base Communication");153 logging_debug("Send: Sending message via Base Communication"); 154 154 return bc->sendMessage( ld->communicationId, message ); 155 155 } … … 157 157 // relay message 158 158 else if ( ld->relay ) { 159 logging_debug("sendMessage: Relaying message to node " 159 160 logging_debug("Send: Relaying message to node " 160 161 << ld->remoteNode.toString() 161 162 << " using relay " << ld->localRelay … … 165 166 LinkDescriptor* rld = getRelayDescriptor(ld->localRelay); 166 167 if (rld==NULL) { 167 logging_error(" sendMessage: Relay descriptor for relay " <<168 ld->localRelay.toString() << " unknown.");168 logging_error("Send: Relay descriptor for relay " << 169 ld->localRelay.toString() << " is unknown."); 169 170 return -1; 170 171 } … … 183 184 } 184 185 185 // route message using overlay186 // error 186 187 else { 187 logging_error("Could not send message descriptor=" << ld ); 188 logging_debug( "sendMessage: Routing message to node " << ld->remoteNode.toString() ); 189 overlayInterface->routeMessage( ld->remoteNode, message ); 190 return 0; 191 } 192 188 logging_error( "Could not send message descriptor=" << ld ); 189 return -1; 190 } 193 191 return -1; 194 192 } … … 1399 1397 LinkDescriptor* rld = getDescriptor( overlayMsg->getRelayLink() ); 1400 1398 logging_force( "Received direct link convert notification for " << rld ); 1399 1400 // set communcation link id and set it up 1401 1401 rld->communicationId = ld->communicationId; 1402 1403 // this is neccessary since this link was a relay link before! 1402 1404 rld->communicationUp = true; 1405 1406 // this is not a relay link anymore! 1403 1407 rld->relay = false; 1404 rld->localRelay = NodeID::UNSPECIFIED;1408 rld->localRelay = NodeID::UNSPECIFIED; 1405 1409 rld->remoteRelay = NodeID::UNSPECIFIED; 1410 1411 // mark used and alive! 1412 rld->markAsUsed(); 1413 rld->markAlive(); 1414 1415 // erase the original descriptor 1406 1416 eraseDescriptor(ld->overlayId); 1407 1417 break; -
source/ariba/utility/addressing/endpoint_set.hpp
r5284 r5406 247 247 /// checks whether two end-points are disjoint 248 248 /// (only check lower level addresses) 249 bool is_disjoint_to( const endpoint_set& set ) const {249 bool disjoint_to( const endpoint_set& set ) const { 250 250 scoped_lock lock(const_cast<boost::mutex&>(io_mutex)); 251 251 BOOST_FOREACH( const mac_address& mac, bluetooth ) … … 254 254 if (set.ip.count(ip_) !=0 ) return false; 255 255 return true; 256 } 257 258 bool intersects_with( const endpoint_set& set ) const { 259 return !disjoint_to(set); 260 } 261 262 bool is_subset_of( const endpoint_set& set ) const { 263 throw "Not implemented!"; 264 return false; 256 265 } 257 266 … … 387 396 this->tcp = rhs.tcp; 388 397 } 398 399 /// checks wheter the two endpoint sets are identical 400 bool operator== ( const endpoint_set& rhs ) const { 401 return (rhs.rfcomm == rfcomm && rhs.ip == ip && rhs.tcp == tcp && 402 rhs.bluetooth == bluetooth); 403 } 404 405 bool operator!= ( const endpoint_set& rhs ) const { 406 return !(*this==rhs); 407 } 389 408 }; 390 409 -
source/ariba/utility/addressing/ip_address.hpp
r5284 r5406 128 128 //--- address info -------------------------------------------------------- 129 129 130 const std::string& type_name() const{130 static const std::string& type_name() { 131 131 return type_name_ip; 132 132 } 133 133 134 const uint16_t type_id() const{134 static const uint16_t type_id() { 135 135 return 0x81DD; 136 136 } … … 148 148 } 149 149 150 bool is_link_local() const { 151 if (addr.is_v4()) return false; 152 return addr.to_v6().is_link_local(); 153 } 154 155 bool is_multicast_link_local() const { 156 if (addr.is_v4()) return false; 157 return addr.to_v6().is_multicast_link_local(); 158 159 } 160 161 bool is_multicast_node_local() const { 162 if (addr.is_v4()) return false; 163 return addr.to_v6().is_multicast_node_local(); 164 } 165 166 167 bool is_multicast_site_local() const { 168 if (addr.is_v4()) return false; 169 return addr.to_v6().is_multicast_site_local(); 170 } 171 150 172 bool is_any() const { 151 173 if (addr.is_v4()) return addr.to_v4() == address_v4::any(); … … 153 175 } 154 176 177 bool is_v4_compatible() const { 178 if (addr.is_v4()) return true; 179 return addr.to_v6().is_v4_compatible(); 180 } 181 182 bool is_v4_mapped() { 183 if (addr.is_v4()) return true; 184 return addr.to_v6().is_v4_mapped(); 185 } 186 155 187 bool is_v4() const { 156 188 return addr.is_v4(); … … 176 208 namespace boost { 177 209 210 // boost hash function 178 211 template<> 179 212 struct hash<ariba::addressing::ip_address>: public std::unary_function<ariba::addressing::ip_address, std::size_t> { -
source/ariba/utility/transport/rfcomm/rfcomm.cpp
r5289 r5406 11 11 #include <deque> 12 12 13 14 13 namespace ariba { 15 14 namespace transport { 15 16 use_logging_cpp(rfcomm) 16 17 17 18 using namespace boost::asio; … … 31 32 public: 32 33 link_info(io_service& io ) : 33 up(false), local(), remote(), socket(io), size(0), buffer(NULL), sending(false) { 34 up(false), local(), remote(), socket(io), connect_retries(0), 35 size(0), buffer(NULL), sending(false) { 34 36 } 35 37 … … 38 40 rfcomm_endpoint local, remote; 39 41 bluetooth::rfcomm::socket socket; 42 int connect_retries; 40 43 41 44 // read buffer … … 50 53 }; 51 54 52 void rfcomm::remove_info(link_info* info) { 53 for (vector<link_info*>::iterator i = links.begin(); i!=links.end();i++) 54 if (*i==info) { 55 delete info; 56 links.erase(i); 57 } 55 void rfcomm::shutdown(link_info* info) { 56 if (info != NULL && info->up) { 57 info->up = false; 58 info->socket.shutdown( bluetooth::rfcomm::socket::shutdown_both ); 59 } 58 60 } 59 61 … … 76 78 rfcomm::rfcomm(uint16_t channel) : 77 79 channel(channel), io(asio_io_service::alloc()) { 80 accept_retries = 0; 78 81 } 79 82 … … 88 91 89 92 // create acceptor 90 cout << "Binding to channel " << channel << endl;93 logging_info( "Binding to channel " << channel ); 91 94 acceptor = new bluetooth::rfcomm::acceptor(io, 92 95 bluetooth::rfcomm::endpoint(bluetooth::rfcomm::get(), channel ) 93 96 ); 94 97 98 send_data = new link_data(); 99 95 100 // start accepting 96 101 start_accept(); … … 98 103 99 104 void rfcomm::stop() { 105 logging_info( "Stopping asio rfcomm" ); 100 106 101 107 } 102 108 103 109 void rfcomm::send(const address_v* remote, const uint8_t* data, size_t size) { 110 104 111 // get end-point 105 112 rfcomm_endpoint endpoint = *remote; … … 107 114 108 115 // try to find established connector 116 logging_debug("Trying to find a already existing link."); 109 117 link_info* info = NULL; 110 118 for (size_t i = 0; i < links.size(); i++) 111 119 if (links[i]->remote.mac() == endpoint.mac()) { 120 logging_debug("Using already established link"); 112 121 info = links[i]; 113 122 break; 114 123 } 115 124 116 // not found? ->try to connect 117 if (info==NULL) { 118 cout << "Connecting to " << endpoint.to_string() << endl; 119 info = new link_info(io); 125 // not found, or not up? ->try to (re-)connect 126 if (info==NULL || !info->up) { 127 logging_debug( "Connecting to " << endpoint.to_string() ); 128 if (info != NULL && !info->up) { 129 logging_debug("Old link is down. Trying to re-establish link."); 130 } else { 131 info = new link_info(io); 132 } 133 info->remote = endpoint; 120 134 info->socket.async_connect( convert(endpoint), boost::bind( 121 135 &rfcomm::handle_connect, this, … … 156 170 157 171 void rfcomm::terminate(const address_v* local, const address_v* remote) { 158 // not supported right now! 172 // get end-point 173 rfcomm_endpoint endpoint = *remote; 174 175 for (size_t i = 0; i < links.size(); i++) 176 if (links[i]->remote.mac() == endpoint.mac()) { 177 178 // close socket 179 links[i]->socket.cancel(); 180 links[i]->socket.close(); 181 links[i]->up = false; 182 break; 183 } 159 184 } 160 185 … … 165 190 void rfcomm::start_accept() { 166 191 167 cout << "Waiting for connections ..." << endl;192 logging_info( "Waiting for connections ..." ); 168 193 169 194 // start accepting a connection … … 181 206 void rfcomm::handle_accept(const error_code& error, link_info* info) { 182 207 if (error) { 183 cout << "Error accepting" << endl; 208 logging_error( "Error waiting for new connections: " << error 209 << ", trying to recover (attempt " << accept_retries << ")"); 184 210 delete info; 211 212 // restart accepting 213 if (accept_retries<3) { 214 accept_retries++; 215 start_accept(); 216 } 185 217 return; 186 218 } … … 191 223 info->remote = convert( info->socket.remote_endpoint() ); 192 224 193 cout << "Accepting incoming connection from " << info->remote.to_string() << endl; 225 logging_debug("Accepting incoming connection from " 226 << info->remote.to_string() ); 194 227 195 228 // add to list … … 208 241 void rfcomm::handle_connect( const error_code& error, link_info* info ) { 209 242 if (error) { 210 cout << "Error connecting ..." << endl; 211 delete info; 212 return; 243 logging_error( "Can not connect. Retrying ... " 244 "(attempt " << info->connect_retries << ")" ); 245 246 // do we retry this connection? yes-> 247 if (info->connect_retries<3) { 248 // increase counter 249 info->connect_retries++; 250 251 // retry connection attempt 252 info->socket.async_connect( convert(info->remote), boost::bind( 253 &rfcomm::handle_connect, this, 254 boost::asio::placeholders::error, info 255 )); 256 257 } else { // no-> delete link and stop 258 return; 259 } 213 260 } 214 261 … … 218 265 info->remote = convert( info->socket.remote_endpoint() ); 219 266 220 cout << "Connected to " << info->remote.to_string() << endl;267 logging_debug( "Connected to " << info->remote.to_string() ); 221 268 222 269 // add to list … … 233 280 // start read 234 281 boost::asio::async_read(info->socket, 282 235 283 // read size of packet 236 284 boost::asio::buffer(info->size_, 4), 285 237 286 // bind handler 238 287 boost::bind( 288 239 289 // bind parameters 240 290 &rfcomm::handle_read_header, this, 291 241 292 // handler parameters 242 293 placeholders::error, placeholders::bytes_transferred, info … … 248 299 link_info* info) { 249 300 301 // handle error 302 if (error) { 303 logging_error("Failed to receive message payload."); 304 shutdown(info); 305 return; 306 } 307 250 308 // ignore errors and wait for all data to be received 251 if ( error ||bytes != 4) return;309 if (bytes != 4) return; 252 310 253 311 // get size … … 255 313 (info->size_[2]<< 8) + (info->size_[3] << 0); 256 314 257 cout << "receive message of size " << info->size << endl;315 logging_debug( "Message header received -> receive message of size " << info->size ); 258 316 259 317 // allocate buffer … … 277 335 link_info* info) { 278 336 279 // ignore errors and wait for all data to be received 280 if (error || bytes != info->size) { 281 if (error) remove_info(info); 337 // check error 338 if (error) { 339 logging_error("Failed to receive message payload."); 340 shutdown(info); 282 341 return; 283 342 } 284 343 285 cout << "received message of size " << info->size << endl; 344 // wait for all data to be received 345 if (bytes != info->size) return; 346 347 logging_debug( "Received message of size " << info->size ); 286 348 287 349 // deliver data … … 296 358 297 359 void rfcomm::start_write( link_info* info ) { 360 boost::mutex::scoped_lock(info->mutex); 361 298 362 // do not start writing if sending is in progress 299 363 if (info->sending || !info->up || info->send_buffer.size()==0) return; … … 302 366 303 367 // safely remove data from deque 304 info->mutex.lock(); 305 link_data data = info->send_buffer.front(); 368 *send_data = info->send_buffer.front(); 306 369 info->send_buffer.pop_front(); 307 info->mutex.unlock();308 370 309 371 boost::array<boost::asio::mutable_buffer, 2> buffer; 310 buffer[0] = boost::asio::buffer( data.size_,4);311 buffer[1] = boost::asio::buffer( data.buffer,data.size);372 buffer[0] = boost::asio::buffer(send_data->size_,4); 373 buffer[1] = boost::asio::buffer(send_data->buffer,send_data->size); 312 374 313 375 // start writing … … 321 383 // handler parameters 322 384 placeholders::error, placeholders::bytes_transferred, 323 info, data.size, data.buffer385 info, send_data->size, send_data->buffer 324 386 ) 325 387 ); … … 332 394 if (error || bytes != (size+4) ) { 333 395 if (error) { 334 cout << "Message sent error" << endl; 335 remove_info(info); 396 logging_error( "Message sent error" ); 397 398 // close socket 399 info->socket.close(); 400 info->up = false; 336 401 } 337 402 return; 338 403 } 339 340 cout << "Message sent" << endl; 404 logging_debug( "Message sent" ); 341 405 342 406 // free buffer -
source/ariba/utility/transport/rfcomm/rfcomm.hpp
r5289 r5406 11 11 #include <boost/asio/io_service.hpp> 12 12 13 #include "ariba/utility/logging/Logging.h" 14 13 15 namespace ariba { 14 16 namespace transport { … … 18 20 19 21 class link_info; 22 class link_data; 20 23 21 24 /** … … 25 28 */ 26 29 class rfcomm : public transport_protocol { 30 use_logging_h(rfcomm) 27 31 public: 28 32 rfcomm( uint16_t channel ); … … 42 46 transport_listener* listener; 43 47 bluetooth::rfcomm::acceptor* acceptor; 48 int accept_retries; 49 link_data* send_data; 44 50 45 51 void start_accept(); … … 60 66 link_info* info, size_t size, uint8_t* buffer ); 61 67 62 void remove_info(link_info* info);68 void shutdown(link_info* info); 63 69 }; 64 70
Note:
See TracChangeset
for help on using the changeset viewer.