Class: Server

Server

Creates a shard server for sending and receiving consigned file shards

new Server(options)

Parameters:
Name Type Description
options object
Properties
Name Type Argument Default Description
identity string Node identity key
database Database
shards Shards
tokenTtl number <optional>
1800000 Expire unused token
Source:

Methods


accept(token, filehash, contact)

Begin accepting data for the given file hash and token
Parameters:
Name Type Description
token string The authorization token created for transfer
filehash string The shard hash to allow for the token
contact array Contact that negotiated the token
Source:

authorize(token, hash)

Validates the given token
Parameters:
Name Type Description
token string
hash string
Source:
Returns:
Type
object

download(req, res)

Pumps the data through to the client
Parameters:
Name Type Description
req http.IncomingMessage
res http.ServerResponse
Source:

reject(token)

Stop accepting data for the given token
Parameters:
Name Type Description
token string The authorization token created for transfer
Source:

upload(req, req)

Receives the data stream and writes it to storage
Parameters:
Name Type Description
req http.IncomingMessage
req http.ServerResponse
Source:

Events


error

Triggered when a error occurs
Parameters:
Name Type Description
error error
Source:

shardDownloaded

Triggered when a shard has finished downloading from this instance
Parameters:
Name Type Description
hash string The hash associated with the download
Source:

shardUploaded

Triggered when a shard has finished uploading to this instance
Parameters:
Name Type Description
hash string The hash associated with the upload
Source: