Simple TCP/IP Communication Lib
This lib creates a wrapper of sorts around the node.js's net.createServer
and net.connect
. It sets up encrypted communication between a client and server using DiffieHellman Key Exchange, and aes-256-cbc
encryption from node.js's crypto
. It also takes care of message compression and splitting.
##Install
npm install ca-net
##API
Wrapper for net.connect
Parameters
Host: string, Address of Server
Port: int, Port of Server
API: function, [optional] Called on('data') will pass arguments
objCon
,Buffer
callback: function, [optional] Called on('connect') will pass arguments
net.Socket
,objCon
Wrapper for net.createServer
Parameters
Port: int, Port to listen on
API: function, [optional] Called on('data') will pass arguments
objCon
,Buffer
callback: function, [optional] Called on('listening') will pass arguments
net.Server
,{'token':objCon}
internal class
internal class
Parameters
objCon: objCon, internal class
data: Buffer, internal class
internal function called at the tail of a recursive
objData.combine
,objData.unpack
,objData.pack
or whenobjData
times out onobjData.ttl
timeout
internal function called to join together data that has been split by
objData.pack
Parameters
aObjData: objData, internal function called to join together data that has been split by
objData.pack
internal function Prepends
data
Buffer with length and writes it socketParameters
data: Buffer, Data to send
internal function Processes Prepended length and split
data
Buffer if longer than length calls .unpack() ondata
creates newobjData
for remainingdata
and calls .recieve() on newobjData
internal function processes
objData.data
before callingobjData.send
zip? > encrypt? > split?Parameters
c: bool, [optional] toEncrypt flag
z: bool, [optional] toZip flag
s: bool, [optional] Special Flag used for pubKey syncing
internal function process
objData.data
before passingobjData.data
toobjData.objCon.API
join? > decrypt? > unzip?
internal class
internal class
Parameters
con: net.Socket, internal class
token: string, [optional]
address: string, [optional]
API: function, [optional]
Handles encryption setup on initial connection
Parameters
c: objCon, Handles encryption setup on initial connection
r: Buffer, Handles encryption setup on initial connection
destroys objCon on time out
updates
objCon.ttl
to keep connection from self destructing
send messages to remote connection
Parameters
msg: Buffer, Message to send to remote connection
flg: bool, internal var for connection initilization
##TODO:
Coding:
create objCon class for uniformity betwen Cli & Servcreate objData class for simulated low level exchangeobjData Send/RecieveobjData ZippingobjData EncryptionobjData pubKey Sync- add functionality for externaly checking if objCon.destruct() has been called
- change .onError() so that host script is informed
Testing / Doc:
Test Send / RecieveTest ZippingTest EncryptionTest Splittingremove cb from source & testingupdate testing w/ random dataTest Zip > Encrypt > Split > Send\Recieve > Join > Decrypt > UnzipTest objConDoc API- Add Example Code
Eventualy:
- Rewrite objData.pack() and objData.unpack() to use a fixed length binnary header instead of dirty string manipulation
####Disclaimer: This is a toy project, and should not be used for production grade anything ... use at your own risk