transport.rst (34602B)
1 .. index:: 2 double: TRANSPORT; subsystem 3 4 .. _TRANSPORT-Subsystem-Dev: 5 6 TRANSPORT 7 ========= 8 9 .. _Address-validation-protocol: 10 11 Address validation protocol 12 --------------------------- 13 14 This section documents how the GNUnet transport service validates 15 connections with other peers. It is a high-level description of the 16 protocol necessary to understand the details of the implementation. It 17 should be noted that when we talk about PING and PONG messages in this 18 section, we refer to transport-level PING and PONG messages, which are 19 different from core-level PING and PONG messages (both in implementation 20 and function). 21 22 The goal of transport-level address validation is to minimize the 23 chances of a successful man-in-the-middle attack against GNUnet peers on 24 the transport level. Such an attack would not allow the adversary to 25 decrypt the P2P transmissions, but a successful attacker could at least 26 measure traffic volumes and latencies (raising the adversaries 27 capabilities by those of a global passive adversary in the worst case). 28 The scenarios we are concerned about is an attacker, Mallory, giving a 29 ``HELLO`` to Alice that claims to be for Bob, but contains Mallory's IP 30 address instead of Bobs (for some transport). Mallory would then forward 31 the traffic to Bob (by initiating a connection to Bob and claiming to be 32 Alice). As a further complication, the scheme has to work even if say 33 Alice is behind a NAT without traversal support and hence has no address 34 of her own (and thus Alice must always initiate the connection to Bob). 35 36 An additional constraint is that ``HELLO`` messages do not contain a 37 cryptographic signature since other peers must be able to edit (i.e. 38 remove) addresses from the ``HELLO`` at any time (this was not true in 39 GNUnet 0.8.x). A basic **assumption** is that each peer knows the set of 40 possible network addresses that it **might** be reachable under (so for 41 example, the external IP address of the NAT plus the LAN address(es) 42 with the respective ports). 43 44 The solution is the following. If Alice wants to validate that a given 45 address for Bob is valid (i.e. is actually established **directly** with 46 the intended target), she sends a PING message over that connection to 47 Bob. Note that in this case, Alice initiated the connection so only 48 Alice knows which address was used for sure (Alice may be behind NAT, so 49 whatever address Bob sees may not be an address Alice knows she has). 50 Bob checks that the address given in the ``PING`` is actually one of 51 Bob's addresses (ie: does not belong to Mallory), and if it is, sends 52 back a ``PONG`` (with a signature that says that Bob owns/uses the 53 address from the ``PING``). Alice checks the signature and is happy if 54 it is valid and the address in the ``PONG`` is the address Alice used. 55 This is similar to the 0.8.x protocol where the ``HELLO`` contained a 56 signature from Bob for each address used by Bob. Here, the purpose code 57 for the signature is ``GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN``. 58 After this, Alice will remember Bob's address and consider the address 59 valid for a while (12h in the current implementation). Note that after 60 this exchange, Alice only considers Bob's address to be valid, the 61 connection itself is not considered 'established'. In particular, Alice 62 may have many addresses for Bob that Alice considers valid. 63 64 The ``PONG`` message is protected with a nonce/challenge against replay 65 attacks (`replay <http://en.wikipedia.org/wiki/Replay_attack>`__) and 66 uses an expiration time for the signature (but those are almost 67 implementation details). 68 69 NAT library 70 .. _NAT-library: 71 72 NAT library 73 ----------- 74 75 The goal of the GNUnet NAT library is to provide a general-purpose API 76 for NAT traversal **without** third-party support. So protocols that 77 involve contacting a third peer to help establish a connection between 78 two peers are outside of the scope of this API. That does not mean that 79 GNUnet doesn't support involving a third peer (we can do this with the 80 distance-vector transport or using application-level protocols), it just 81 means that the NAT API is not concerned with this possibility. The API 82 is written so that it will work for IPv6-NAT in the future as well as 83 current IPv4-NAT. Furthermore, the NAT API is always used, even for 84 peers that are not behind NAT --- in that case, the mapping provided is 85 simply the identity. 86 87 NAT traversal is initiated by calling ``GNUNET_NAT_register``. Given a 88 set of addresses that the peer has locally bound to (TCP or UDP), the 89 NAT library will return (via callback) a (possibly longer) list of 90 addresses the peer **might** be reachable under. Internally, depending 91 on the configuration, the NAT library will try to punch a hole (using 92 UPnP) or just \"know\" that the NAT was manually punched and generate 93 the respective external IP address (the one that should be globally 94 visible) based on the given information. 95 96 The NAT library also supports ICMP-based NAT traversal. Here, the other 97 peer can request connection-reversal by this peer (in this special case, 98 the peer is even allowed to configure a port number of zero). If the NAT 99 library detects a connection-reversal request, it returns the respective 100 target address to the client as well. It should be noted that 101 connection-reversal is currently only intended for TCP, so other plugins 102 **must** pass ``NULL`` for the reversal callback. Naturally, the NAT 103 library also supports requesting connection reversal from a remote peer 104 (``GNUNET_NAT_run_client``). 105 106 Once initialized, the NAT handle can be used to test if a given address 107 is possibly a valid address for this peer (``GNUNET_NAT_test_address``). 108 This is used for validating our addresses when generating PONGs. 109 110 Finally, the NAT library contains an API to test if our NAT 111 configuration is correct. Using ``GNUNET_NAT_test_start`` **before** 112 binding to the respective port, the NAT library can be used to test if 113 the configuration works. The test function act as a local client, 114 initialize the NAT traversal and then contact a ``gnunet-nat-server`` 115 (running by default on ``gnunet.org``) and ask for a connection to be 116 established. This way, it is easy to test if the current NAT 117 configuration is valid. 118 119 .. _Distance_002dVector-plugin: 120 121 Distance-Vector plugin 122 ---------------------- 123 124 The Distance Vector (DV) transport is a transport mechanism that allows 125 peers to act as relays for each other, thereby connecting peers that 126 would otherwise be unable to connect. This gives a larger connection set 127 to applications that may work better with more peers to choose from (for 128 example, File Sharing and/or DHT). 129 130 The Distance Vector transport essentially has two functions. The first 131 is \"gossiping\" connection information about more distant peers to 132 directly connected peers. The second is taking messages intended for 133 non-directly connected peers and encapsulating them in a DV wrapper that 134 contains the required information for routing the message through 135 forwarding peers. Via gossiping, optimal routes through the known DV 136 neighborhood are discovered and utilized and the message encapsulation 137 provides some benefits in addition to simply getting the message from 138 the correct source to the proper destination. 139 140 The gossiping function of DV provides an up to date routing table of 141 peers that are available up to some number of hops. We call this a 142 fisheye view of the network (like a fish, nearby objects are known while 143 more distant ones unknown). Gossip messages are sent only to directly 144 connected peers, but they are sent about other knowns peers within the 145 \"fisheye distance\". Whenever two peers connect, they immediately 146 gossip to each other about their appropriate other neighbors. They also 147 gossip about the newly connected peer to previously connected neighbors. 148 In order to keep the routing tables up to date, disconnect notifications 149 are propagated as gossip as well (because disconnects may not be 150 sent/received, timeouts are also used remove stagnant routing table 151 entries). 152 153 Routing of messages via DV is straightforward. When the DV transport is 154 notified of a message destined for a non-direct neighbor, the 155 appropriate forwarding peer is selected, and the base message is 156 encapsulated in a DV message which contains information about the 157 initial peer and the intended recipient. At each forwarding hop, the 158 initial peer is validated (the forwarding peer ensures that it has the 159 initial peer in its neighborhood, otherwise the message is dropped). 160 Next the base message is re-encapsulated in a new DV message for the 161 next hop in the forwarding chain (or delivered to the current peer, if 162 it has arrived at the destination). 163 164 Assume a three peer network with peers Alice, Bob and Carol. Assume that 165 166 :: 167 168 Alice <-> Bob and Bob <-> Carol 169 170 are direct (e.g. over TCP or UDP transports) connections, but that Alice 171 cannot directly connect to Carol. This may be the case due to NAT or 172 firewall restrictions, or perhaps based on one of the peers respective 173 configurations. If the Distance Vector transport is enabled on all three 174 peers, it will automatically discover (from the gossip protocol) that 175 Alice and Carol can connect via Bob and provide a \"virtual\" Alice <-> 176 Carol connection. Routing between Alice and Carol happens as follows; 177 Alice creates a message destined for Carol and notifies the DV transport 178 about it. The DV transport at Alice looks up Carol in the routing table 179 and finds that the message must be sent through Bob for Carol. The 180 message is encapsulated setting Alice as the initiator and Carol as the 181 destination and sent to Bob. Bob receives the messages, verifies that 182 both Alice and Carol are known to Bob, and re-wraps the message in a new 183 DV message for Carol. The DV transport at Carol receives this message, 184 unwraps the original message, and delivers it to Carol as though it came 185 directly from Alice. 186 187 SMTP plugin 188 .. _SMTP-plugin: 189 190 SMTP plugin 191 ----------- 192 193 .. todo:: Update? 194 195 This section describes the new SMTP transport plugin for GNUnet as it 196 exists in the 0.7.x and 0.8.x branch. SMTP support is currently not 197 available in GNUnet 0.9.x. This page also describes the transport layer 198 abstraction (as it existed in 0.7.x and 0.8.x) in more detail and gives 199 some benchmarking results. The performance results presented are quite 200 old and maybe outdated at this point. For the readers in the year 2019, 201 you will notice by the mention of version 0.7, 0.8, and 0.9 that this 202 section has to be taken with your usual grain of salt and be updated 203 eventually. 204 205 - Why use SMTP for a peer-to-peer transport? 206 207 - SMTPHow does it work? 208 209 - How do I configure my peer? 210 211 - How do I test if it works? 212 213 - How fast is it? 214 215 - Is there any additional documentation? 216 217 .. _Why-use-SMTP-for-a-peer_002dto_002dpeer-transport_003f: 218 219 Why use SMTP for a peer-to-peer transport? 220 ------------------------------------------ 221 222 There are many reasons why one would not want to use SMTP: 223 224 - SMTP is using more bandwidth than TCP, UDP or HTTP 225 226 - SMTP has a much higher latency. 227 228 - SMTP requires significantly more computation (encoding and decoding 229 time) for the peers. 230 231 - SMTP is significantly more complicated to configure. 232 233 - SMTP may be abused by tricking GNUnet into sending mail 234 to non-participating third parties. 235 236 So why would anybody want to use SMTP? 237 238 - SMTP can be used to contact peers behind NAT boxes (in virtual 239 private networks). 240 241 - SMTP can be used to circumvent policies that limit or prohibit 242 peer-to-peer traffic by masking as \"legitimate\" traffic. 243 244 - SMTP uses E-mail addresses which are independent of a specific IP, 245 which can be useful to address peers that use dynamic IP addresses. 246 247 - SMTP can be used to initiate a connection (e.g. initial address 248 exchange) and peers can then negotiate the use of a more efficient 249 protocol (e.g. TCP) for the actual communication. 250 251 In summary, SMTP can for example be used to send a message to a peer 252 behind a NAT box that has a dynamic IP to tell the peer to establish a 253 TCP connection to a peer outside of the private network. Even an 254 extraordinary overhead for this first message would be irrelevant in 255 this type of situation. 256 257 .. _How-does-it-work_003f: 258 259 How does it work? 260 ----------------- 261 262 When a GNUnet peer needs to send a message to another GNUnet peer that 263 has advertised (only) an SMTP transport address, GNUnet base64-encodes 264 the message and sends it in an E-mail to the advertised address. The 265 advertisement contains a filter which is placed in the E-mail header, 266 such that the receiving host can filter the tagged E-mails and forward 267 it to the GNUnet peer process. The filter can be specified individually 268 by each peer and be changed over time. This makes it impossible to 269 censor GNUnet E-mail messages by searching for a generic filter. 270 271 .. _How-do-I-configure-my-peer_003f: 272 273 How do I configure my peer? 274 --------------------------- 275 276 First, you need to configure ``procmail`` to filter your inbound E-mail 277 for GNUnet traffic. The GNUnet messages must be delivered into a pipe, 278 for example ``/tmp/gnunet.smtp``. You also need to define a filter that 279 is used by ``procmail`` to detect GNUnet messages. You are free to 280 choose whichever filter you like, but you should make sure that it does 281 not occur in your other E-mail. In our example, we will use 282 ``X-mailer: GNUnet``. The ``~/.procmailrc`` configuration file then 283 looks like this: 284 285 :: 286 287 :0: 288 * ^X-mailer: GNUnet 289 /tmp/gnunet.smtp 290 # where do you want your other e-mail delivered to 291 # (default: /var/spool/mail/) 292 :0: /var/spool/mail/ 293 294 After adding this file, first make sure that your regular E-mail still 295 works (e.g. by sending an E-mail to yourself). Then edit the GNUnet 296 configuration. In the section ``SMTP`` you need to specify your E-mail 297 address under ``EMAIL``, your mail server (for outgoing mail) under 298 ``SERVER``, the filter (X-mailer: GNUnet in the example) under 299 ``FILTER`` and the name of the pipe under ``PIPE``. The completed 300 section could then look like this: 301 302 .. code-block:: text 303 304 EMAIL = me@mail.gnu.org MTU = 65000 SERVER = mail.gnu.org:25 FILTER = 305 "X-mailer: GNUnet" PIPE = /tmp/gnunet.smtp 306 307 .. todo:: set highlighting for this code block properly. 308 309 Finally, you need to add ``smtp`` to the list of ``TRANSPORTS`` in the 310 ``GNUNETD`` section. GNUnet peers will use the E-mail address that you 311 specified to contact your peer until the advertisement times out. Thus, 312 if you are not sure if everything works properly or if you are not 313 planning to be online for a long time, you may want to configure this 314 timeout to be short, e.g. just one hour. For this, set ``HELLOEXPIRES`` 315 to ``1`` in the ``GNUNETD`` section. 316 317 This should be it, but you may probably want to test it first. 318 319 .. _How-do-I-test-if-it-works_003f: 320 321 How do I test if it works? 322 -------------------------- 323 324 Any transport can be subjected to some rudimentary tests using the 325 ``gnunet-transport-check`` tool. The tool sends a message to the local 326 node via the transport and checks that a valid message is received. 327 While this test does not involve other peers and can not check if 328 firewalls or other network obstacles prohibit proper operation, this is 329 a great testcase for the SMTP transport since it tests pretty much 330 nearly all of the functionality. 331 332 ``gnunet-transport-check`` should only be used without running 333 ``gnunetd`` at the same time. By default, ``gnunet-transport-check`` 334 tests all transports that are specified in the configuration file. But 335 you can specifically test SMTP by giving the option 336 ``--transport=smtp``. 337 338 Note that this test always checks if a transport can receive and send. 339 While you can configure most transports to only receive or only send 340 messages, this test will only work if you have configured the transport 341 to send and receive messages. 342 343 .. _How-fast-is-it_003f: 344 345 How fast is it? 346 --------------- 347 348 We have measured the performance of the UDP, TCP and SMTP transport 349 layer directly and when used from an application using the GNUnet core. 350 Measuring just the transport layer gives the better view of the actual 351 overhead of the protocol, whereas evaluating the transport from the 352 application puts the overhead into perspective from a practical point of 353 view. 354 355 The loopback measurements of the SMTP transport were performed on three 356 different machines spanning a range of modern SMTP configurations. We 357 used a PIII-800 running RedHat 7.3 with the Purdue Computer Science 358 configuration which includes filters for spam. We also used a Xenon 2 359 GHZ with a vanilla RedHat 8.0 sendmail configuration. Furthermore, we 360 used qmail on a PIII-1000 running Sorcerer GNU Linux (SGL). The numbers 361 for UDP and TCP are provided using the SGL configuration. The qmail 362 benchmark uses qmail's internal filtering whereas the sendmail 363 benchmarks relies on procmail to filter and deliver the mail. We used 364 the transport layer to send a message of b bytes (excluding transport 365 protocol headers) directly to the local machine. This way, network 366 latency and packet loss on the wire have no impact on the timings. n 367 messages were sent sequentially over the transport layer, sending 368 message i+1 after the i-th message was received. All messages were sent 369 over the same connection and the time to establish the connection was 370 not taken into account since this overhead is minuscule in practice --- 371 as long as a connection is used for a significant number of messages. 372 373 +--------------+----------+----------+----------+----------+----------+ 374 | Transport | UDP | TCP | SMTP | SMTP (RH | SMTP | 375 | | | | (Purdue | 8.0) | (SGL | 376 | | | | s | | qmail) | 377 | | | | endmail) | | | 378 +==============+==========+==========+==========+==========+==========+ 379 | 11 bytes | 31 ms | 55 ms | 781 s | 77 s | 24 s | 380 +--------------+----------+----------+----------+----------+----------+ 381 | 407 bytes | 37 ms | 62 ms | 789 s | 78 s | 25 s | 382 +--------------+----------+----------+----------+----------+----------+ 383 | 1,221 bytes | 46 ms | 73 ms | 804 s | 78 s | 25 s | 384 +--------------+----------+----------+----------+----------+----------+ 385 386 The benchmarks show that UDP and TCP are, as expected, both 387 significantly faster compared with any of the SMTP services. Among the 388 SMTP implementations, there can be significant differences depending on 389 the SMTP configuration. Filtering with an external tool like procmail 390 that needs to re-parse its configuration for each mail can be very 391 expensive. Applying spam filters can also significantly impact the 392 performance of the underlying SMTP implementation. The microbenchmark 393 shows that SMTP can be a viable solution for initiating peer-to-peer 394 sessions: a couple of seconds to connect to a peer are probably not even 395 going to be noticed by users. The next benchmark measures the possible 396 throughput for a transport. Throughput can be measured by sending 397 multiple messages in parallel and measuring packet loss. Note that not 398 only UDP but also the TCP transport can actually loose messages since 399 the TCP implementation drops messages if the ``write`` to the socket 400 would block. While the SMTP protocol never drops messages itself, it is 401 often so slow that only a fraction of the messages can be sent and 402 received in the given time-bounds. For this benchmark we report the 403 message loss after allowing t time for sending m messages. If messages 404 were not sent (or received) after an overall timeout of t, they were 405 considered lost. The benchmark was performed using two Xeon 2 GHZ 406 machines running RedHat 8.0 with sendmail. The machines were connected 407 with a direct 100 MBit Ethernet connection. Figures udp1200, tcp1200 and 408 smtp-MTUs show that the throughput for messages of size 1,200 octets is 409 2,343 kbps, 3,310 kbps and 6 kbps for UDP, TCP and SMTP respectively. 410 The high per-message overhead of SMTP can be improved by increasing the 411 MTU, for example, an MTU of 12,000 octets improves the throughput to 13 412 kbps as figure smtp-MTUs shows. Our research paper [Transport2014]_ has 413 some more details on the benchmarking results. 414 415 Bluetooth plugin 416 .. _Bluetooth-plugin: 417 418 Bluetooth plugin 419 ---------------- 420 421 This page describes the new Bluetooth transport plugin for GNUnet. The 422 plugin is still in the testing stage so don't expect it to work 423 perfectly. If you have any questions or problems just post them here or 424 ask on the IRC channel. 425 426 - What do I need to use the Bluetooth plugin transport? 427 428 - BluetoothHow does it work? 429 430 - What possible errors should I be aware of? 431 432 - How do I configure my peer? 433 434 - How can I test it? 435 436 .. _What-do-I-need-to-use-the-Bluetooth-plugin-transport_003f: 437 438 What do I need to use the Bluetooth plugin transport? 439 ----------------------------------------------------- 440 441 If you are a GNU/Linux user and you want to use the Bluetooth transport 442 plugin you should install the ``BlueZ`` development libraries (if they 443 aren't already installed). For instructions about how to install the 444 libraries you should check out the BlueZ site 445 (`http://www.bluez.org <http://www.bluez.org/>`__). If you don't know if 446 you have the necessary libraries, don't worry, just run the GNUnet 447 configure script and you will be able to see a notification at the end 448 which will warn you if you don't have the necessary libraries. 449 450 .. _How-does-it-work2_003f: 451 452 .. todo:: Change to unique title? 453 454 How does it work2? 455 ------------------ 456 457 The Bluetooth transport plugin uses virtually the same code as the WLAN 458 plugin and only the helper binary is different. The helper takes a 459 single argument, which represents the interface name and is specified in 460 the configuration file. Here are the basic steps that are followed by 461 the helper binary used on GNU/Linux: 462 463 - it verifies if the name corresponds to a Bluetooth interface name 464 465 - it verifies if the interface is up (if it is not, it tries to bring 466 it up) 467 468 - it tries to enable the page and inquiry scan in order to make the 469 device discoverable and to accept incoming connection requests *The 470 above operations require root access so you should start the 471 transport plugin with root privileges.* 472 473 - it finds an available port number and registers a SDP service which 474 will be used to find out on which port number is the server listening 475 on and switch the socket in listening mode 476 477 - it sends a HELLO message with its address 478 479 - finally it forwards traffic from the reading sockets to the STDOUT 480 and from the STDIN to the writing socket 481 482 Once in a while the device will make an inquiry scan to discover the 483 nearby devices and it will send them randomly HELLO messages for peer 484 discovery. 485 486 .. _What-possible-errors-should-I-be-aware-of_003f: 487 488 What possible errors should I be aware of? 489 ------------------------------------------ 490 491 *This section is dedicated for GNU/Linux users* 492 493 Well there are many ways in which things could go wrong but I will try 494 to present some tools that you could use to debug and some scenarios. 495 496 - ``bluetoothd -n -d`` : use this command to enable logging in the 497 foreground and to print the logging messages 498 499 - ``hciconfig``: can be used to configure the Bluetooth devices. If you 500 run it without any arguments it will print information about the 501 state of the interfaces. So if you receive an error that the device 502 couldn't be brought up you should try to bring it manually and to see 503 if it works (use ``hciconfig -a hciX up``). If you can't and the 504 Bluetooth address has the form 00:00:00:00:00:00 it means that there 505 is something wrong with the D-Bus daemon or with the Bluetooth 506 daemon. Use ``bluetoothd`` tool to see the logs 507 508 - ``sdptool`` can be used to control and interrogate SDP servers. If 509 you encounter problems regarding the SDP server (like the SDP server 510 is down) you should check out if the D-Bus daemon is running 511 correctly and to see if the Bluetooth daemon started correctly(use 512 ``bluetoothd`` tool). Also, sometimes the SDP service could work but 513 somehow the device couldn't register its service. Use 514 ``sdptool browse [dev-address]`` to see if the service is registered. 515 There should be a service with the name of the interface and GNUnet 516 as provider. 517 518 - ``hcitool`` : another useful tool which can be used to configure the 519 device and to send some particular commands to it. 520 521 - ``hcidump`` : could be used for low level debugging 522 523 .. _How-do-I-configure-my-peer2_003f: 524 525 .. todo:: Fix name/referencing now that we're using Sphinx. 526 527 How do I configure my peer2? 528 ---------------------------- 529 530 On GNU/Linux, you just have to be sure that the interface name 531 corresponds to the one that you want to use. Use the ``hciconfig`` tool 532 to check that. By default it is set to hci0 but you can change it. 533 534 A basic configuration looks like this: 535 536 :: 537 538 [transport-bluetooth] 539 # Name of the interface (typically hciX) 540 INTERFACE = hci0 541 # Real hardware, no testing 542 TESTMODE = 0 TESTING_IGNORE_KEYS = ACCEPT_FROM; 543 544 In order to use the Bluetooth transport plugin when the transport 545 service is started, you must add the plugin name to the default 546 transport service plugins list. For example: 547 548 :: 549 550 [transport] ... PLUGINS = dns bluetooth ... 551 552 If you want to use only the Bluetooth plugin set *PLUGINS = bluetooth* 553 554 On Windows, you cannot specify which device to use. The only thing that 555 you should do is to add *bluetooth* on the plugins list of the transport 556 service. 557 558 .. _How-can-I-test-it_003f: 559 560 How can I test it? 561 ------------------ 562 563 If you have two Bluetooth devices on the same machine and you are using 564 GNU/Linux you must: 565 566 - create two different file configuration (one which will use the first 567 interface (*hci0*) and the other which will use the second interface 568 (*hci1*)). Let's name them *peer1.conf* and *peer2.conf*. 569 570 - run *gnunet-core -c peerX.conf -i* in order to generate the peers 571 private keys. The **X** must be replace with 1 or 2. 572 573 - run *gnunet-arm -c peerX.conf -s -i=transport* in order to start the 574 transport service. (Make sure that you have \"bluetooth\" on the 575 transport plugins list if the Bluetooth transport service doesn't 576 start.) 577 578 - run *gnunet-core -c peer1.conf -i* to get the first peer's ID. If 579 you already know your peer ID (you saved it from the first command), 580 this can be skipped. 581 582 - run *gnunet-transport -c peer2.conf -p=PEER1_ID -s* to start sending 583 data for benchmarking to the other peer. 584 585 This scenario will try to connect the second peer to the first one and 586 then start sending data for benchmarking. 587 588 If you have two different machines and your configuration files are good 589 you can use the same scenario presented on the beginning of this 590 section. 591 592 Another way to test the plugin functionality is to create your own 593 application which will use the GNUnet framework with the Bluetooth 594 transport service. 595 596 .. _The-implementation-of-the-Bluetooth-transport-plugin: 597 598 The implementation of the Bluetooth transport plugin 599 ---------------------------------------------------- 600 601 This page describes the implementation of the Bluetooth transport 602 plugin. 603 604 First I want to remind you that the Bluetooth transport plugin uses 605 virtually the same code as the WLAN plugin and only the helper binary is 606 different. Also the scope of the helper binary from the Bluetooth 607 transport plugin is the same as the one used for the WLAN transport 608 plugin: it accesses the interface and then it forwards traffic in both 609 directions between the Bluetooth interface and stdin/stdout of the 610 process involved. 611 612 The Bluetooth plugin transport could be used both on GNU/Linux and 613 Windows platforms. 614 615 - Linux functionality 616 617 - Pending Features 618 619 .. _Linux-functionality: 620 621 Linux functionality 622 ^^^^^^^^^^^^^^^^^^^ 623 624 In order to implement the plugin functionality on GNU/Linux I used the 625 BlueZ stack. For the communication with the other devices I used the 626 RFCOMM protocol. Also I used the HCI protocol to gain some control over 627 the device. The helper binary takes a single argument (the name of the 628 Bluetooth interface) and is separated in two stages: 629 630 .. _THE-INITIALIZATION: 631 632 .. todo:: 'THE INITIALIZATION' should be in bigger letters or stand out, not 633 starting a new section? 634 635 THE INITIALIZATION 636 ^^^^^^^^^^^^^^^^^^ 637 638 - first, it checks if we have root privileges (*Remember that we need 639 to have root privileges in order to be able to bring the interface up 640 if it is down or to change its state.*). 641 642 - second, it verifies if the interface with the given name exists. 643 644 **If the interface with that name exists and it is a Bluetooth 645 interface:** 646 647 - it creates a RFCOMM socket which will be used for listening and call 648 the *open_device* method 649 650 On the *open_device* method: 651 652 - creates a HCI socket used to send control events to the device 653 654 - searches for the device ID using the interface name 655 656 - saves the device MAC address 657 658 - checks if the interface is down and tries to bring it UP 659 660 - checks if the interface is in discoverable mode and tries to make 661 it discoverable 662 663 - closes the HCI socket and binds the RFCOMM one 664 665 - switches the RFCOMM socket in listening mode 666 667 - registers the SDP service (the service will be used by the other 668 devices to get the port on which this device is listening on) 669 670 - drops the root privileges 671 672 **If the interface is not a Bluetooth interface the helper exits with 673 a suitable error** 674 675 .. _THE-LOOP: 676 677 THE LOOP 678 ^^^^^^^^ 679 680 The helper binary uses a list where it saves all the connected neighbour 681 devices (*neighbours.devices*) and two buffers (*write_pout* and 682 *write_std*). The first message which is send is a control message with 683 the device's MAC address in order to announce the peer presence to the 684 neighbours. Here are a short description of what happens in the main 685 loop: 686 687 - Every time when it receives something from the STDIN it processes the 688 data and saves the message in the first buffer (*write_pout*). When 689 it has something in the buffer, it gets the destination address from 690 the buffer, searches the destination address in the list (if there is 691 no connection with that device, it creates a new one and saves it to 692 the list) and sends the message. 693 694 - Every time when it receives something on the listening socket it 695 accepts the connection and saves the socket on a list with the 696 reading sockets. 697 698 - Every time when it receives something from a reading socket it parses 699 the message, verifies the CRC and saves it in the *write_std* buffer 700 in order to be sent later to the STDOUT. 701 702 So in the main loop we use the select function to wait until one of the 703 file descriptor saved in one of the two file descriptors sets used is 704 ready to use. The first set (*rfds*) represents the reading set and it 705 could contain the list with the reading sockets, the STDIN file 706 descriptor or the listening socket. The second set (*wfds*) is the 707 writing set and it could contain the sending socket or the STDOUT file 708 descriptor. After the select function returns, we check which file 709 descriptor is ready to use and we do what is supposed to do on that kind 710 of event. *For example:* if it is the listening socket then we accept a 711 new connection and save the socket in the reading list; if it is the 712 STDOUT file descriptor, then we write to STDOUT the message from the 713 *write_std* buffer. 714 715 To find out on which port a device is listening on we connect to the 716 local SDP server and search the registered service for that device. 717 718 *You should be aware of the fact that if the device fails to connect to 719 another one when trying to send a message it will attempt one more time. 720 If it fails again, then it skips the message.* *Also you should know 721 that the transport Bluetooth plugin has support for*\ **broadcast 722 messages**\ *.* 723 724 .. _Details-about-the-broadcast-implementation: 725 726 Details about the broadcast implementation 727 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 728 729 First I want to point out that the broadcast functionality for the 730 CONTROL messages is not implemented in a conventional way. Since the 731 inquiry scan time is too big and it will take some time to send a 732 message to all the discoverable devices I decided to tackle the problem 733 in a different way. Here is how I did it: 734 735 - If it is the first time when I have to broadcast a message I make an 736 inquiry scan and save all the devices' addresses to a vector. 737 738 - After the inquiry scan ends I take the first address from the list 739 and I try to connect to it. If it fails, I try to connect to the next 740 one. If it succeeds, I save the socket to a list and send the message 741 to the device. 742 743 - When I have to broadcast another message, first I search on the list 744 for a new device which I'm not connected to. If there is no new 745 device on the list I go to the beginning of the list and send the 746 message to the old devices. After 5 cycles I make a new inquiry scan 747 to check out if there are new discoverable devices and save them to 748 the list. If there are no new discoverable devices I reset the 749 cycling counter and go again through the old list and send messages 750 to the devices saved in it. 751 752 **Therefore**: 753 754 - every time when I have a broadcast message I look up on the list for 755 a new device and send the message to it 756 757 - if I reached the end of the list for 5 times and I'm connected to all 758 the devices from the list I make a new inquiry scan. *The number of 759 the list's cycles after an inquiry scan could be increased by 760 redefining the MAX_LOOPS variable* 761 762 - when there are no new devices I send messages to the old ones. 763 764 Doing so, the broadcast control messages will reach the devices but with 765 delay. 766 767 *NOTICE:* When I have to send a message to a certain device first I 768 check on the broadcast list to see if we are connected to that device. 769 If not we try to connect to it and in case of success we save the 770 address and the socket on the list. If we are already connected to that 771 device we simply use the socket. 772 773 .. _Pending-features: 774 775 Pending features 776 ^^^^^^^^^^^^^^^^ 777 778 - Implement a testcase for the helper : *The testcase consists of a 779 program which emulates the plugin and uses the helper. It will 780 simulate connections, disconnections and data transfers.* 781 782 If you have a new idea about a feature of the plugin or suggestions 783 about how I could improve the implementation you are welcome to comment 784 or to contact me. 785 786 .. _WLAN-plugin: 787 788 WLAN plugin 789 ----------- 790 791 This section documents how the wlan transport plugin works. Parts which 792 are not implemented yet or could be better implemented are described at 793 the end. 794 795 .. [Transport2014] https://bib.gnunet.org/date.html#paper_5fshort2014