Changeset - 13603ac261f1
[Not reviewed]
default
0 3 0
Laman - 7 years ago 2018-02-19 22:46:08

minor enhancements
3 files changed with 4 insertions and 4 deletions:
0 comments (0 inline, 0 general)
protocol.md
Show inline comments
 
# Protocol #
 
# Protocol v0.1 #
 

	
 
[Communication protocol proposal. Not yet fully implemented and still expected to change.]
 

	
 
Nodes communicate by exchanging messages through network sockets. Basic message format is simple:
 

	
 
		json-length: ABC
 
		bin-length: DEF
 
		{... JSON payload ...}
 
		... binary payload ...
 

	
 
`ABC` is the JSON payload length (decimal integer), `DEF` is the binary payload length. JSON payload always contains a "command" field.
 

	
 
@@ -31,25 +31,25 @@ Initiates communication between the clie
 

	
 

	
 
### <a name="req"></a>req ###
 
Requests hashes or a data chunk from the server.
 

	
 
#### Params ####
 
- {hash, data} dataType
 

	
 
hash
 
- [(int) i0, ...] index: list of requested node keys from the HashTree
 

	
 
data
 
- (int) index: requested data block number in the data file. Returns blockSize bytes starting at blockSize * index.
 
- [(int) i0, ...] index: list of requested data blocks from the data file. Returns blockSize bytes starting at blockSize * i.
 

	
 
#### Responses ####
 
- [send](#send)
 
- [err](#err)
 

	
 

	
 
### <a name="send"></a>send ####
 
Sends data. Can be a client action or a response to a request.
 

	
 
#### Params ####
 
- {hash, data} dataType
 
- index: see [req](#req)
src/morevna.sh
Show inline comments
 
@@ -7,23 +7,23 @@
 

	
 
# generate certificate
 
# openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=name"
 

	
 
set -e
 
DIRNAME=`dirname $0`
 

	
 
sudo losetup -f ~/ext2.img
 
sudo cryptsetup open --type=luks /dev/loop0 ext2luks
 
sudo mount /dev/mapper/ext2luks ~/temp
 

	
 
sudo rdiff-backup -v 5 ~/Dokumenty ~/temp/Dokumenty
 
sudo rdiff-backup -v 5 --exclude '**/__pycache__/' ~/Projekty ~/temp/Projekty
 
sudo rdiff-backup -v 5 --exclude-regexp '/__pycache__/' ~/Projekty ~/temp/Projekty
 
sudo rdiff-backup -v 5 ~/Obrázky ~/temp/Obrázky
 

	
 
sudo umount /dev/mapper/ext2luks
 
sudo cryptsetup close ext2luks
 
sudo losetup -d /dev/loop0
 

	
 
echo
 

	
 
python $DIRNAME/morevna.py build ~/ext2.bin ~/ext2.img
 
python $DIRNAME/morevna.py push --tree ~/ext2.bin ~/ext2.img
src/networkers.py
Show inline comments
 
@@ -32,17 +32,17 @@ class NetworkReader:
 

	
 
class NetworkWriter:
 
	def __init__(self,stream):
 
		self._stream=stream
 

	
 
	def writeMsg(self,*args):
 
		msg=self.prepMsg(*args)
 
		self._stream.write(msg)
 
		self._stream.flush()
 
		stats.logSent(msg)
 

	
 
	def prepMsg(self,jsonData,binData=b""):
 
		jsonData=bytes(json.dumps(jsonData)+"\n",encoding="utf-8")
 
		jsonData=bytes(json.dumps(jsonData,separators=(',',':'))+"\n",encoding="utf-8")
 
		jsonLength=bytes("json-length: "+str(len(jsonData))+"\n",encoding="utf-8")
 
		binLength=bytes("bin-length: "+str(len(binData))+"\n",encoding="utf-8")
 

	
 
		return b"".join((jsonLength,binLength,jsonData,binData))
0 comments (0 inline, 0 general)