-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotos
76 lines (60 loc) · 1.93 KB
/
protos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
General form:
[proto header, byte version, ...]
v1 proto [char mType, uint pktid, ...]
mTypes:
DH requests
DH encapsulated
AES encapsulated
DH requests:
[all DH handshake messages]
DH encapsulated:
[PKI handshakes]
PKI encapsulated:
[AES handshake]
[DHT messages]
AES encapsulated:
[data messages]
protocol:
get packet & tear off header
from pktid, enum to message type
decode the inner protocol
throw event for keys if needed?
(enum type)
Max pkt: 65,507 bytes (chunked)
Min maximum pkt size: 576 bytes -> 512 useable
Common MTU: 1500 -> 1408
# Sent to initiate a file transfer
Init get -> [char mType, ushort id, 160bit hash]
# Reply to initiation with file metadata
Init get resp -> [char mType, ushort id, 160bit hash, ulong chunkCount, ulong chunkSize]
I/O request -> [char mType, ushort id, 160bit hash, chunkNo]
I/O resend -> [char mType, ushort id, 160bit hash, chunkNo, slices(ushort? arr)]
Awk -> [char mType, ushort awkID]
I/O send -> [char mType, ushort id, 160bit hash, chunkNo, sliceNo, DATA]
File request -> [char mType, ushort id, 160bit hash]
File response -> [char mType, ushort id, ulonglong size (8 byte), [160bit hashes]]
#NOTE -> Only supports 3274 hashes. This will need pkt continuation for files > 63.94gb @ 20MB/chunk
Encryption:
[enc. flag, payload[type, id, payload]]
Walkthrough:
Client Peer
# ANY PACKET
Packet(type, id, payload)
Awk(id)
On failure to receive awk:
Resends packet after 3*ave ping
# HANDSHAKE
Sends nonce enc. w/ pub key
If (client is known) return enc. nonce
else return /dev/urand
# SEARCH
# FILE TRANSFER
GetFile(hash)
FileResponse(hash, name, size, [chunk hashes])
FileStatus(hash)
CompletedChunks(chunk flags)
I/O request(hash, chunkNo)
I/O send(hash, chunkNo, sliceNo, DATA)
I/O send(hash, chunkNo, sliceNo, DATA)
# Max of 323 slices per chunk (20MB / 65,000B)
I/O resend(hash, chunkNo, slices(bitarr))