started work on new gossip streaming protocol
This commit is contained in:
parent
ba8ba6d3d8
commit
a55055e720
0
static-data/default-plugins/torgossip/bootstrap.txt
Normal file
0
static-data/default-plugins/torgossip/bootstrap.txt
Normal file
33
static-data/default-plugins/torgossip/main.py
Executable file
33
static-data/default-plugins/torgossip/main.py
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
"""
|
||||||
|
Onionr - Private P2P Communication
|
||||||
|
|
||||||
|
This default plugin allows users to encrypt/decrypt messages without using blocks
|
||||||
|
"""
|
||||||
|
import locale
|
||||||
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from threading import Thread
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
"""
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
plugin_name = 'torgossip'
|
||||||
|
from server import start_server
|
||||||
|
|
||||||
|
|
||||||
|
def on_init(api, data=None):
|
||||||
|
print("starting gossip transport")
|
||||||
|
Thread(target=start_server, daemon=True).start()
|
||||||
|
|
66
static-data/default-plugins/torgossip/server.py
Normal file
66
static-data/default-plugins/torgossip/server.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
"""
|
||||||
|
Onionr - Private P2P Communication
|
||||||
|
|
||||||
|
Gossip plugin server, multiplexing using gevent
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
|
||||||
|
import selectors
|
||||||
|
import socket
|
||||||
|
|
||||||
|
import filepaths
|
||||||
|
"""
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def start_server():
|
||||||
|
|
||||||
|
sel = selectors.DefaultSelector()
|
||||||
|
|
||||||
|
def accept(sock, mask):
|
||||||
|
conn, addr = sock.accept() # Should be ready
|
||||||
|
print('accepted', conn, 'from', addr)
|
||||||
|
conn.setblocking(False)
|
||||||
|
sel.register(conn, selectors.EVENT_READ, read)
|
||||||
|
|
||||||
|
def read(conn, mask):
|
||||||
|
data = conn.recv(1000) # Should be ready
|
||||||
|
if data:
|
||||||
|
print('echoing', repr(data), 'to', conn)
|
||||||
|
conn.send(data) # Hope it won't block
|
||||||
|
else:
|
||||||
|
print('closing', conn)
|
||||||
|
sel.unregister(conn)
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
socket_file = filepaths.identifyhome.identify_home() + "torgossip.sock"
|
||||||
|
try:
|
||||||
|
os.remove(socket_file)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
sock.bind(socket_file)
|
||||||
|
sock.listen(100)
|
||||||
|
sock.setblocking(False)
|
||||||
|
sel.register(sock, selectors.EVENT_READ, accept)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
events = sel.select()
|
||||||
|
for key, mask in events:
|
||||||
|
callback = key.data
|
||||||
|
callback(key.fileobj, mask)
|
||||||
|
if __name__ == "__main__":
|
||||||
|
start_server()
|
Loading…
Reference in New Issue
Block a user