xp2ppeertracker v1.0.2
WindRibbon P2P Peer Tracker (XP2PPeerTracker)
Introduction
In WindRibbon P2P system, after established the exchange network (via VPN). We have to track the internal IP address of each peer. This module implemented the peer register/keep alive functionality.
Requirements
Here is the software requirement:
Package | Version |
---|---|
NodeJS | >= 8.7.0 |
Installation
Type following command to install this package.
npm install -g xp2ppeertracker
Then you can use following command to start the server/client.
# Server.
xp2ppeertracker-server -c "[Configuration Path]"
# Client.
xp2ppeertracker-client -c "[Configuration Path]"
Hooks (server)
Overview
To make this module more scalable, you have to use external script to implement authentication/renew and offline processes.
Such an external script is called a "hook". In the server side, once the client triggered some events, corresponding hooks will be called.
Authentication
User/password authentication (PAP)
The user/password authentication hook should accepts two arguments - the user and the password. The hook should do authentication and exit with code 0x00 if succeed.
Here is an example:
#!/bin/sh
#
# User/password credential authentication hook.
#
# (C) 2015 - 2018 The WindRibbon Authors. All rights reserved.
#
# Get the credential.
USER="$1"
PASSWORD="$2"
# Do authentication.
if [ <Authentication succeed> ]; then
exit 0
else
exit 1
fi
Renew
Once the server side received "renew" request from the client, the hook will be called. The hook should accepts four parameters - the user name, remote IP address, remote port and remote IP family. Once renew succeed, this hook should exit with code 0x00.
Here is an example:
#!/bin/sh
#
# User renew hook.
#
# (C) 2015 - 2018 The WindRibbon Authors. All rights reserved.
#
# Get the parameters.
USER="$1"
REMOTE_ADDRESS="$2"
REMOTE_PORT="$3"
REMOTE_FAMILY="$4"
# Renew.
# TODO: Write your own logic here.
exit 0
Offline
Once a client disconnected from the server, the "offline" hook will be triggered. The hook is like the "renew" hook but do the opposite things.
Configuration
Here is the template of server configuration:
{
"server": {
"bind": {
"address": "0.0.0.0", // Bind address.
"port": 4518 // Bind port.
},
"timeout": 30000, // (Optional) TCP timeout (default: not set).
"keep-alive": true, // (Optional) TCP SO_KEEPALIVE option (default: true).
"no-delay": true, // (Optional) TCP TCP_NODELAY option (default: true).
"buffer": {
"incoming": 524288, // (Optional) The incoming TCP buffer size (default: 524288).
"outgoing": 524288 // (Optional) The outgoing TCP buffer size (default: 524288).
}
},
"hooks": {
"authentication": {
"pap": {
"cwd": "/", // The working directory of the user/password authentication hook.
"command": "[..]/pap.sh" // The hook path.
}
},
"renew": {
"cwd": "/", // The working directory of the renew hook.
"command": "[..]/renew.sh" // The hook path.
},
"offline": {
"cwd": "/", // The working directory of the offline hook.
"command": "[..]/offline.sh" // The hook path.
}
}
}
Here is the template of client configuration:
{
"socket": {
"destination": {
"address": "localhost", // Destination address.
"port": 4518 // Destination port.
},
"timeout": 30000, // (Optional) TCP timeout (default: not set).
"keep-alive": true, // (Optional) TCP SO_KEEPALIVE option (default: true).
"no-delay": true // (Optional) TCP TCP_NODELAY option (default: true).
},
"buffer": {
"incoming": 524288, // (Optional) The incoming TCP buffer size (default: 524288).
"outgoing": 524288 // (Optional) The outgoing TCP buffer size (default: 524288).
},
"heartbeat": {
"interval": 1000, // The interval of sending "heartbeat" request.
"size": 64 // (Optional) The data size of each heartbeat request (default: 64).
},
"renew": {
"interval": 5000 // The interval of sending "renew" request.
},
"credential": {
"type": "pap", // Authentication method (currently, only "pap" is available).
"user": "xiaojsoft", // The user name.
"password": "123456" // The password.
}
}
See "examples" directory for more details.