Skip to content
iljahPublic

About

See README

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

p2pIM
=====

Peer-to-peer instant messaging system using proof-of-work (PoW)
for spam protection. Larger messages require better PoW and it
decays with time, making room for new messages.


Prototype server 2 usage
--------------

Start first server with

$ ./server2.py --ui-addr 127.0.1.0 --comm-addr 127.0.1.0

and open http://127.0.1.0:8000 in your browser. Type something
and press enter to send a message. After (refreshing the page
in) about 10 s you should see its proof of work increase (lower
is better). You can change PoW update interval with --update-pow.
If you send 3 or 4 more messages, one(s) with largest PoW should
disappear. You can change how much memory is available for
messages with --mem. If you keep sending more messages, their
nonces should increase from aaaaaaaaaa to give better PoW so that
they replace existing messages. Or you can wait for PoW of
previous messages to decay so that worse PoW is sufficient for
new messages to be accepted.


Start second server with

$ ./server2.py --ui-addr 127.0.2.0 --comm-addr 127.0.2.0

and open http://127.0.2.0:8000 in your browser. Add first
server's communication URL (http://127.0.1.0:6000) to peer list
of second server and refresh after few seconds to see messages
of first server transferred to second one. You can change
polling interval of peers with --peer-interval.


You can also use curl to communicate with servers on their
communication port:

$ curl http://127.0.2.0:6000/peers
http://127.0.1.0:6000

$ curl http://127.0.2.0:6000/ids
20790578
9615130
70494565
17993413

$ curl http://127.0.2.0:6000/get/70494565
["0","20261010082449","aaaaaaaaaa","ab530a13e459","message"]

Wire format is described in class Message_v0 of messages.py.
You can use generate1.py to generate messages in correct
format:

$ curl http://127.0.2.0:6000/put/$(urlencode \
    $(./generate1.py "another message"))
Required PoW: 0x00235572

In case of error (!= ok), try with better (smaller) PoW:

$ curl http://127.0.2.0:6000/put/$(urlencode \
    $(./generate1.py "another message" --pow 10000))
ok



Prototype server 1 usage
-----

Print message with payload `hello world` using generate1.py:

$ ./generate1.py "hello world"
["0","20251109124254","aaaaaaaaaa","b94d27b9934d","hello world"]

Start server1.py in one tab:

./server1.py

and send it message(s) in another tab using generate1.py and socat:

$ ./generate1.py test1 | tr -d \\n | socat - TCP:localhost:8765
ok
$ ./generate1.py test2 | tr -d \\n | socat - TCP:localhost:8765
ok

Query messages from server1.py with control message __message__:

$ ./generate1.py __messages__ | tr -d \\n | socat - TCP:localhost:8765
["0","20251109105926","aaaaaaaaaa","1b4f0e985197","test1"]
["0","20251109105930","aaaaaaaaaa","60303ae22b99","test2"]

See `./generate1.py --help` for options.


Transferring messages between server 1s
-------------------------------------

Start another server1.py on port 8764:

./server1.py --port 8764

and send it all messages from first server running on port 8765:

$ for m in $(./generate1.py  __messages__ | tr -d \\n | socat - TCP:localhost:8765); do echo $m | tr -d \\n | socat - TCP:localhost:8764; done
ok
ok


Implementation / specification
------------------------------

See Message_v0 class in messages.py for description of message format
and `./server1.py --help` for options.

About

See README

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages