• Stars
    star
    151
  • Rank 246,057 (Top 5 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Securely locate peers without central servers

Overview

Scout is a library enabling two users to contact each other over the Internet using only their respective public keys. The Bittorrent distributed hash table (DHT) is used to store and retrieve contact information. Scout can also be used to store and retrieve short messages from the DHT so that peers can communicate even if they are never online at the same time.

Prerequisites

Scout requires Boost 1.58 or newer and Libsodium 1.0 or newer

Building

Scout uses Boost.Build version 2 to build. For information on installing BBv2 see the Boost.Build manual. By default scout uses the versions of boost and libsodium which are installed on the system. If you are building on Windows you will need to specify the paths to the boost and libsodium source trees using the BOOST_ROOT and SODIUM_ROOT environment variables. Example commands to build scout on Windows:

C:\scout> set BOOST_ROOT=C:\boost_1_60_0
C:\scout> set SODIUM_ROOT=C:\libsodium-1.0.8
C:\scout> bjam toolset=msvc-14

Setting up a DHT session

Most users will want to use the dht_session class to easily set up a DHT node which can be used with the rest of scout's functions. To start a node create an instance of dht_session and call the start function.

scout::dht_session ses;
ses.start();

The start function will start a DHT node in a separate thread and return immediately. To stop the DHT node call the stop function.

ses.stop();

This function will block until the dht node thread has exited. If stop is not called explicitly it will be called from the dht_session destructor.

Generating a key pair

Scout provides the generate_keypair function to generate a new ed25519 key pair.

std::pair<scout::secret_key, scout::public_key> keypair = scout::generate_keypair();

Callbacks

The scout API involves many callback functions. When using the dht_session class it is important to keep in mind that callbacks will be invoked in the DHT node's thread rather than the main thread of your application. This means you need to be careful when accessing your application's data structures from a callback. Ideally callbacks will carry a copy of any data they might need to store in the DHT and post notifications to the main application event loop for new data retrieved from the DHT.

Storage lifetime

Data stored in the DHT can only be expected to remain there for up to two hours. It is recommended that data be stored/synchronized roughly once an hour.

Synchronizing contact information

Scout stores contact information as a vector of entries. Each entry must be assigned an id which is unique within that vector. The contents of the entries are left up to the application. Scout encrypts the entry vector before storing it in the DHT so applications do not need to encrypt each entry's contents.

To communicate entries between peers, scout uses a synchronize operation which retrieves the existing vector of entries from the DHT then writes a new vector with whatever updates the application specifies. To synchronize with a peer you need to have a shared secret to use as a key. Scout provides a key exchange function with uses Diffie-Hellman to generate a shared secret from the user's private key and a remote peer's public key.

scout::secret_key shared_secret = scout::key_exchange(my_secret_key, remote_public_key);
ses.synchronize(shared_secret, entries, entry_updated, finalize_entries, sync_finished);

The entries vector should contain the entries which the application is currently aware of. The entry_updated callback will be invoked when a new or updated entry is retrieved from the DHT. The finalize_entries callback will be invoked after all updates have been retrieved and before the updated entry vector is stored in the DHT, it provides the application a final opportunity to update the entries. The sync_finished callback is invoked once all store requests have completed, any resources associated with the operation may be freed by this function.

Storing offline messages

Scout supports storing messages in the DHT so that a peer can retrieve them later even if the originator has gone offline. Messages are limited to 1000 bytes each. Scout does not encrypt message contents, the application is expected to have it's own message encryption scheme. Messages are stored in the DHT using the hash of their content as the key, thus the content of a message cannot be changed. A series of messages are stored as a linked list which can be retrieved using just the hash of the most recently stored message. Message lists are always retrieved in last-in-first-out order.

The first step is to create a message list.

scout::list_head message_list;

You can then add one-or-more messages to the list.

scout::list_token msg_token = message_list.push_front(message_contents);

The list_token contains the hash of the next message in the list, which corresponds to the previously added message. It should be stored alongside the message contents so that the message can be periodically stored in the DHT.

ses.put(msg_token, message_contents, put_finished);

The msg_token must match the one returned from push_front for the given message. The storage backing the message contents must remain valid until the put_finished callback is invoked.

Retrieving offline messages

To retrieve a list of offline messages you first must obtain the hash of the first message. The sender can get this hash from the list_head.

hash head_hash = message_list.head();

Typically this hash will be included in the contents of an entry. Once the receiving peer has the hash it can retrieve the first message.

ses.get(head_hash, message_received);

The message_received callback is passed the message contents along with the hash of the next message in the list.

More Repositories

1

libutp

uTorrent Transport Protocol library
C++
1,074
star
2

bootstrap-dht

DHT bootstrap server
C++
401
star
3

bittorrent.org

HTML
356
star
4

sqltorrent

C
265
star
5

go-btfs

BTFS - The First Scalable Decentralized Storage System - A Foundational Platform for Decentralized Applications
HTML
231
star
6

btc

Command-line BitTorrent remote control (btc)
Python
153
star
7

webui

JavaScript
112
star
8

bencode

Python
75
star
9

libbtdht

C++
38
star
10

Helix

BitTorrent Tracker
C++
32
star
11

okui

An okay OpenGL-based UI framework.
C++
30
star
12

btfs-dashboard

A Client helps users to manage their BTFS nodes
JavaScript
25
star
13

scraps

Useful scraps of C++.
C++
21
star
14

BTIPs

The BTFS Improvement Proposal repository
18
star
15

sync_api_sample

Python
11
star
16

ut-signing-tool

C++
10
star
17

libbtutils

C++
10
star
18

sync_slack

BitTorrent Sync sample integration with Slack
Python
8
star
19

utorrent_help

Utorrent and bittorrent help files
CSS
7
star
20

simon

A tool to judge your code
Python
7
star
21

sitrep

Public-facing status reports for your infrastructure.
Python
7
star
22

librtmp

Ticket #5945
C
6
star
23

tornado-sqs

Python
6
star
24

social

Home of the social media library for Bittorrent Apps
JavaScript
5
star
25

widgets

The Bittorrent Widgets package is a collection of widgets that integrate with the Apps for BitTorrent SDK, and simplify common behaviors.
JavaScript
4
star
26

org.bittorrent.scribble

Clojure library for generating Graphite graph URLs
Clojure
4
star
27

boost_1_44_0

C++
3
star
28

live-build-environments

Build environments for our stuff
Shell
3
star
29

btfs-airdrop

Solidity
3
star
30

generator-btapp

yeoman webapp generator fork for a btapp sites
JavaScript
3
star
31

ipboard_proxy

Ruby
2
star
32

btfs-encryption

Go
2
star
33

jshackle

Helper macros for JNI programming
C++
2
star
34

docker-kubectl

Docker container for kubectl
1
star
35

live-ci-tools

A [small] collection of CI tools
Python
1
star
36

SDL

Fork of SDL with some minor tweaks
C
1
star
37

go-btfs-cmds

Go
1
star
38

cookbook-bt-foo

Ruby
1
star
39

libtommath-test

C
1
star
40

bigcouch-bin

bigcouch binary repo
Python
1
star
41

mongoose-context-protected-plugin

JavaScript
1
star
42

btfs-vault

Cheque protocol of BTFS node
JavaScript
1
star