add the python servers (http and websocket) and some notes
parent
9e0319acb0
commit
6e9ea52e1e
@ -0,0 +1,6 @@
|
|||||||
|
Create fake contacts
|
||||||
|
####################
|
||||||
|
Run `window.getAccountManager().addMockContact()` in the debugger console. This will print the fake contact public key.
|
||||||
|
Behind the scenes, this also emulates that we're already received the contact's prekeys by generating them and saving them in our db.
|
||||||
|
Copy/paste that public key in the search bar to start chatting.
|
||||||
|
The messages should have a "v" tick to mark that the message was correctly sent (you need to run the httpserver from /mockup_servers)
|
@ -0,0 +1,54 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
import time
|
||||||
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
|
||||||
|
# HTTPRequestHandler class
|
||||||
|
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
|
||||||
|
def do_PUT(self):
|
||||||
|
print('got PUT request to ' + self.path)
|
||||||
|
# add some latency
|
||||||
|
time.sleep(2)
|
||||||
|
# Send response status code
|
||||||
|
self.send_response(201)
|
||||||
|
|
||||||
|
# Send headers
|
||||||
|
#self.send_header()
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
|
message = self.rfile.read(int(self.headers.get('Content-Length'))).decode('UTF-8')
|
||||||
|
|
||||||
|
print(message)
|
||||||
|
|
||||||
|
# Send message back to client
|
||||||
|
#message = "ok"
|
||||||
|
# Write content as utf-8 data
|
||||||
|
#self.wfile.write(bytes(message, "utf8"))
|
||||||
|
|
||||||
|
# GET
|
||||||
|
def do_GET(self):
|
||||||
|
# Send response status code
|
||||||
|
time.sleep(1)
|
||||||
|
self.send_response(200)
|
||||||
|
|
||||||
|
# Send headers
|
||||||
|
self.send_header('Content-type','text/html')
|
||||||
|
self.end_headers()
|
||||||
|
|
||||||
|
# Send message back to client
|
||||||
|
message = "Hello world!"
|
||||||
|
# Write content as utf-8 data
|
||||||
|
self.wfile.write(bytes(message, "utf8"))
|
||||||
|
return
|
||||||
|
|
||||||
|
def run():
|
||||||
|
print('starting server...')
|
||||||
|
|
||||||
|
# Server settings
|
||||||
|
# Choose port 8080, for port 80, which is normally used for a http server, you need root access
|
||||||
|
server_address = ('127.0.0.1', 80)
|
||||||
|
httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
|
||||||
|
print('running server...')
|
||||||
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
|
run()
|
@ -0,0 +1,6 @@
|
|||||||
|
http server for mocking up sending message to the server and getting a response back.
|
||||||
|
websocket server for mocking up opening a connection to receive messages from the server.
|
||||||
|
|
||||||
|
run either server with
|
||||||
|
`sudo python3 <script>`
|
||||||
|
(sudo is required for port 80) but both can't be run at the same time.
|
@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# WS server example
|
||||||
|
import time
|
||||||
|
import asyncio
|
||||||
|
import websockets
|
||||||
|
|
||||||
|
async def hello(websocket, path):
|
||||||
|
print(f"connection done {path}")
|
||||||
|
|
||||||
|
# created by executing in js:
|
||||||
|
# protomessage = new textsecure.protobuf.WebSocketMessage({type: textsecure.protobuf.WebSocketMessage.Type.REQUEST, request: {id:99, verb:'PUT', path:'/api/v1/queue/empty', body:null }})
|
||||||
|
# new Uint8Array(encoded.encode().toArrayBuffer())
|
||||||
|
|
||||||
|
signature = websocket.request_headers.get('signature')
|
||||||
|
|
||||||
|
if not signature:
|
||||||
|
print("no signature provided")
|
||||||
|
|
||||||
|
keep_alive_bytes = bytes([8, 1, 18, 28, 10, 3, 80, 85, 84, 18, 19, 47, 97, 112, 105, 47, 118, 49, 47, 113, 117, 101, 117, 101, 47, 101, 109, 112, 116, 121, 32, 99])
|
||||||
|
my_bytes = keep_alive_bytes
|
||||||
|
counter = 0
|
||||||
|
while(True):
|
||||||
|
print("sending keepalive")
|
||||||
|
await websocket.send(my_bytes)
|
||||||
|
response = await websocket.recv()
|
||||||
|
print(f"response: {response}")
|
||||||
|
time.sleep(30)
|
||||||
|
counter = counter + 1
|
||||||
|
|
||||||
|
start_server = websockets.serve(hello, 'localhost', 80)
|
||||||
|
|
||||||
|
asyncio.get_event_loop().run_until_complete(start_server)
|
||||||
|
asyncio.get_event_loop().run_forever()
|
Loading…
Reference in New Issue