Skip to content
Snippets Groups Projects
Commit 5caf5cc9 authored by Wistauder, Martin's avatar Wistauder, Martin
Browse files

Updated server and client, as well as protocol

parent 98d66526
Branches
No related tags found
No related merge requests found
......@@ -2,16 +2,64 @@ import sys
sys.path.insert(0, '../..')
sys.path.insert(0, '../../shared/netcode')
import queue
import grpc
from shared.netcode.netcode_pb2 import *
from shared.netcode.netcode_pb2_grpc import NotifierComStub
usage = "Usage:\n- Sender:\n ./client.py 1\n- Receiver:\n ./client.py 0"
def sendMessage(stub, msg):
request = SendMessageRequest(message=msg)
request = Message(content=msg)
response = stub.SendMessage(request)
if __name__ == "__main__":
# Check enough args
if len(sys.argv) < 2:
print("Error: Not enough arguments.")
print(usage)
exit(1)
########################################################################
# SETTINGS
########################################################################
is_sender = sys.argv[1]
########################################################################
# print info
print("-- SENDER --" if is_sender else "-- RECEIVER --")
with grpc.insecure_channel('localhost:8080') as channel:
try:
grpc.channel_ready_future(channel).result(timeout=5)
except grpc.FutureTimeoutError:
print("Error: Connection to server failed.")
exit(1)
stub = NotifierComStub(channel)
sendMessage(stub, "test")
if is_sender:
response = stub.OpenComm(OpenCommRequest(challenge=1))
print(response)
sendQueue = queue.SimpleQueue()
response_future = stub.SendMessage.future(iter(sendQueue.get, None))
sendQueue.put_nowait(Message(content="init test"))
print("Starting Prompt:")
while True:
text = input()
if text == "":
print("Stopping...")
break
print("Sending:", text)
sendQueue.put_nowait(Message(content=text))
else:
response = stub.AnswerComm(AnswerCommRequest(challenge=1))
print(response)
for message in stub.ReceiveMessage(Nothing()):
print(message.content)
......@@ -6,8 +6,8 @@
1. Authenticate to the server and establish communication.
1. A tells the server to open a communication.
1. A calculates the challenge.
2. A sends the challenge to the server.
2. A sends an id_code to the server.
3. A gets a comm_id from the server.
2. B tells the server to answer A's communication request.
1. B receives A's challenge.
2. B answers the solution to the server.
......@@ -15,4 +15,4 @@
2. Generate and exchange an ephemeral key.
3. Instantiate symmetric encryption using the ephemeral key.
4. Authenticate each other directly.
5. Check communication transcript (avoid malicious server).
\ No newline at end of file
5. (?) Check communication transcript (avoid malicious server).
\ No newline at end of file
......@@ -8,8 +8,25 @@ from shared.netcode.netcode_pb2_grpc import *
class NotifierService(NotifierComServicer):
def SendMessage(self, request, context):
print(request.message)
def OpenComm(self, request, context):
# TODO: append id_code to list
# TODO: wait for id_code answered
# TODO: return comm_id
return CommResponse()
def AnswerComm(self, request, context):
# TODO: check if if_code can be answered
# TODO: return comm_id
return CommResponse()
def ReceiveMessage(self, request, context):
# TODO: read comm_id and wait for messages
yield Message(content="test")
def SendMessage(self, request_iterator, context):
for msg in request_iterator:
# TODO: read comm_id and route message
print(msg.content)
return Nothing()
......
syntax = "proto3";
package netcode;
service NotifierCom {
rpc SendMessage (SendMessageRequest) returns (Nothing);
service NotifierCommunication {
rpc Open (OpenRequest) returns (CommResponse);
rpc Answer (AnswerRequest) returns (CommResponse);
rpc SendMessage (stream Message) returns (Nothing);
rpc ReceiveMessage (ReceiveRequest) returns (stream Message);
}
message SendMessageRequest {
string message = 1;
message ReceiveRequest {
uint64 comm_id = 1;
}
message Message {
uint64 comm_id = 1;
string content = 2;
}
message OpenRequest {
int64 id_code = 1;
}
message AnswerRequest {
int64 id_code = 1;
}
message CommResponse {
uint64 comm_id = 1;
}
message Nothing {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment