Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Nodejs Peer to Peer over TCP
- -----------------------------------
- ### Bootup
- - Check if an .userrc file is present, if not
- - calculate the hash of the user's ipv4 and create an user name, notify the user to reset it with `node start.js -u username`
- - Scan all the available ip's listening on the `PORT`
- - Start a tcp server on `PORT`
- ### Scanning
- - Create a socket and ping all ips starting from `192.168.x.y`, where x is either hard-coded or retrived from users ipv4 address, on `PORT`
- - A server recieves, a `{type: "ping"}`, and responds back with a `{type: "pong", nick: user_name}`, this pong object, combined with ip is stored in an inmemory database
- ### Connecting
- - The user is provided with a prompt to type in commands
- - To connect an user types in `/connect <ip>/<nick>`, in case of nick, the ip is retrived from database
- - The initiator creates a connection socket with the provided `ip` and default `PORT`
- - The client server, on recieving a connection, gets the `remoteAddress` , and creates a connection with the ip as `remoteAddress`
- - Rest of the communication is like a normal chat
- - `/leave <nick>` stops the client connection
- ### Implementation Pain Points
- - Given the same code running on initiator and reciever, how to the achieve points 2 and 3 at the same time.
- - A socket is full duplex (HTW do I utilize that information), Is the above point necessary, if not what is the correct way
- - Multiple users connecting to an user, Need to maintain a list of `client sockets` and maybe instead of `/connect <ip>`, use `/tell <ip>/<nick> message` and destroy the connection after one message
- - PGP encryption FTW
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement