Skip to content
vkefallinos edited this page Jan 13, 2015 · 7 revisions

P2P Domain Registration - First Run

On every boot the system checks if the system has a public ip address addressable from the web so it can start a supernode instance.If yes everything is ok.If not then the system checks if UPNP is enabled on the modem.If yes then it makes a request to the modem to redirect port 50000 to the local ip(if it's already used it increments 50000 by 10 until it finds an unused port).If upnp is disabled then it'll ask the user to either enable it or use a public supernode instance. Whatever happens it stores the supernode instance ip:port for later use on the domain registration or update with tvcouch.

On a new peernode a user enters peer.local for the first time on his browser and he/she is asked to get a p2p domain for his server. For example the user wants to register the domain "myhome.p2p".

  1. "myhome.p2p" is searched on a peerhub server if it is already registered. 1.1) If it isn't then "myhome.p2p" is registered on the peerhub server (and replicated to other peerhubs) with a public key that is created with
kadnode-ctl --auth-gen-keys
that produces
public:aaf55e367307a92a6

secret:b9d0fae5e67b11k

and store a json file with a PUT request in the form of
{
domain:"myhome.p2p",
public:"aaf55e367307a92a6",
ip:"xxx.xxx.xxx.xxx",
supernode:"xxx.xxx.xxx.xxx:50000",
signature:""
}
a signature is also given with challenge made from tvcouch server that proves the knowledge of the secret key.

1.2) If it is already registered inform the user to choose another domain and go to step 1. 2) Start kadnode and announce the main domain "myhome.p2p" with the secret key "using the command":https://github.com/mwarning/KadNode/issues/23

kadnode --auth-add-skey "myhome.p2p:b9d0fae5e67b11k"

3) Every time the system's public ip is changed we update the ip field on the tvcouch server and the supernode field if supernode runs locally(dyndns). Now if another tvcouch node searches on DHT for "myhome.p2p:aaf55e367307a92a6" then a custom dns entry on the raspberry dns server will be recorded. So if the "myhome.p2p" will redirect to the to the ip of the previous node. For a domain lookup there are two ways for the system to find the authorized domain(the domain with the correct public key). The user exchanges the public key through a trusted communication method and then runs the command

kadnode-ctl lookup myhome.p2p:<public_key>
The system does a GET request to the tvcouch server for "myhome" and is returned with the json file mentioned above.

User Registration
When a new user wants to register his name on the configured node he is asked to input a username and a password.If the username already exists on the domain(checks if db named exists) then it rejects the username and informs the user, else with the credentials used: a private and public key is created using the cryptico javascript library. a new couchdb user and two couchdb databases are created using the username as the database name.The databases are called "" and "public-".The "public-" is a write only database by the user's friends ,that is made possible with "dropbox databases in rcouch":https://github.com/rcouch/rcouch/wiki/Write-only-databases . The first is the users private database that can be read only by him/her and the second is the database that is used for exchanging encrypted messages with other authorized users(friends). the user is asked if he wants to make his/her profile public on tvcouch server so it can be easier and faster to be searched for on the tvcouch server. If yes then a PUT request is made to the users database of the tvcouch server with a json file in the form of

{
  username:"bill",
  user_public_key:"",
  domain:"myhome.p2p",
  avatar:"http://url/to/picture",
  public_data:{any data the user wants to be public such as age,gender etc},
  signature:
}

the user is announced as a subdomain on the DHT network with the command

kadnode-ctl announce bill.myhome.p2p

an edge subprocess to the supernode is started to create a secure encrypted communication tunnel for friend requests that uses the user's public key as the encryption key.This is done by running

 edge -d n2n-bill -c bill -k  -a y.y.y.y -l xxx.xxx.xxx.xxx:50000

y.y.y.y is generated by calculations made with the username and is the local vpn address.


Search for a user and friend request

A user can be searched either in a fully decentralized way, or semicentralized , or centralized.

  • In the fully decentralized way the searcher has to know through a safe communication method the following:
  1. the domain
  2. the domain's public key
  3. the user's name
  4. the user's public key
  5. the domain's supernode if UPNP on the user is not enabled So the commands needed with the above knowledge are

kadnode-ctl lookup ..p2p:
edge -d n2n--  -c  -k  -a y.y.y.y -l ..p2p:50000

When this happens the searcher can do a put request with his/her info (the same as the above) to the software running that will inform the user of the friend request by adding a friend request json document in the user's db.The info given from the searcher is(encrypted with user's public key ):


{
  username:,
  domain:,
  domain_public_key:
  user_public_key:,
  supernode:,
  #friendly_account:
}

The friendly_account has write only permissions to "public-" db and the password is also used for the edge encryption password.

  • The semicentralized way needs only the knowledge of the full address (..p2p) of the user and his/her public key. The info below are asked from the tvcouch server
  1. the domain's public key
  2. the domain's supernode if UPNP on the user is not enabled The same commands as above are made.
  • The centralized way needs the user searched to have a public profile on tvcouch server. The searcher either knows the full address of the user or just the username will be returned with results matching the requested query.
    The same commands as above are made.

Friend acceptance

When the friend request is accepted by the user , it uses the info given by the friend to connect to the friend's node and put an accepted message to friend's public db. A filtered replication document is created for the new friendship.


Share posts with specific users

Every post has an array of users that are allowed to see the post and based on this the filtered replication happens.

Clone this wiki locally