Using json for data interchange
Each message is a header with some max size
Interface Actions
Join = 0
Leave = 1
Insert = 2
Query = 3
Peer Actions
Add = 4
Remove = 5
Files = 6
Download = 7
Upload = 8
Have = 9
Error Codes
ErrOK = 0
ErrConnected = 1
ErrDisconnected = 2
ErrFileExists = 3
ErrFileMissing = 4
ErrBadPermission = 5
We tell the peer to join the network.
{
"HostName": "<HostName>",
"PortNumber": "<PortNumber>",
"Action": 0,
}
We tell the peer to leave the network
{
"HostName": "<HostName>",
"PortNumber": "<PortNumber>",
"Action": 1
}
Giving the peer the path to a file to insert
{
"HostName": "<HostName>",
"PortNumber": "<PortNumber>",
"Action": 2,
"Files":
[
{
"FileName": "<FileName>",
}
]
}
We tell the peer to leave the network
{
"HostName": "<HostName>",
"PortNumber": "<PortNumber>",
"Action": 3
}
The peers responds with a status json object
{
"numFiles": <numFiles>,
"local": [<frActionPresentLocally>, <frActionPresentLocally>, ...],
"system": [<frActionPresent>, <frActionPresent>, ...],
"leastReplication": [<minimumReplicationLevel>, <minimumReplicationLevel>, ...],
"weightedLeastReplication": [<averageReplicationLevel>, <averageReplicationLevel>, ...]
}
When a joins the network, it send out a message that it's joining and a list of its Files.
{
"HostName": "<HostName>",
"PortNumber": "<PortNumber>",
"Action": 4,
}
This is followed by the file list
{
"Files":
[
{
"file": "<FileName>",
"chunks": "[<chunkNumber>, <chunkNumber>, ...]"
},
{
"file": "<FileName>",
"chunks": "[<chunkNumber>, <chunkNumber>, ...]"
}, ...
]
}
{
"HostName": "<HostName>",
"PortNumber": "<PortNumber>",
"Action": 5
}
The peers respond with a file list.
{
"HostName": "<HostName>",
"PortNumber": "<PortNumber>",
"Action": 6,
}
This is followed by the file list
{
"Files":
[
{
"FileName": "<FileName>",
"chunks": "[<chunkNumber>, <chunkNumber>, ...]"
},
{
"FileName": "<FileName>",
"chunks": "[<chunkNumber>, <chunkNumber>, ...]"
}, ...
]
}
Each peer will then update the status of the Files it has, and send out requests to download the Files it doesn't have
{
"HostName": "<HostName>",
"PortNumber": "<PortNumber>",
"Action": 7,
"Files":
[
{
"FileName": "<FileName>",
"chunks": [<Filesize>, <chunkNumber>]
}
]
}
{
"HostName": "<HostName>",
"PortNumber": "<PortNumber>",
"Action": 8,
"Files":
[
{
"FileName": "<FileName>",
"chunks": [<Filesize>, <chunkNumber>]
}
]
}
Peer messages whenever it receives a new chunk
{
"HostName": "<HostName>",
"PortNumber": "<PortNumber>",
"Action": 9,
"Files":
[
{
"FileName": "<FileName>",
"chunks": [<Filesize>, <chunkNumber>]
}
]
}