Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from src.main.User import *
- from src.netw.InternetPacket import Packet, cleanData
- from src.netw.LocalSockets import WebSocketConnection
- import threading
- K1 = DiffieHellmanKey()
- K2 = DiffieHellmanKey()
- K3 = DiffieHellmanKey()
- K4 = DiffieHellmanKey()
- K1.generateSharedKey(K2.publicKey)
- K2.generateSharedKey(K1.publicKey)
- K3.generateSharedKey(K4.publicKey)
- K4.generateSharedKey(K3.publicKey)
- N1 = Node("127.0.0.1", K1)
- N2 = Node("127.0.0.2", K2)
- N3 = Node("127.0.0.3", K3)
- N4 = Node("127.0.0.4", K4)
- Circuit1 = Circuit("CIRCUIT1", [N1, N2])
- Circuit2 = Circuit("CIRCUIT1", [N3, N4])
- ExampleTable = ForwardingTable()
- ExampleTable.addEntry("CIRCUIT1", N1)
- ExampleTable.addEntry("CIRCUIT2", N2)
- ExampleTable.addEntry("CIRCUIT3", N3)
- ExampleTable.addEntry("CIRCUIT4", N4)
- User1 = User(
- 1,
- "User1",
- [RSAKeys(fileName="TestKey1"), RSAKeys(fileName="TestKey1")],
- "d8cd7bae-0b80-4a71-a7e5-22f728016311",
- ForwardingTable(),
- Queue(),
- Contacts(),
- MessagesDB(),
- )
- User1Public = PublicUser(
- 1, "User1", [User1.encryptionKeys.publicKey, User1.signingKeys.publicKey], Circuit()
- )
- User2 = User(
- 2,
- "User2",
- [RSAKeys(fileName="TestKey2"), RSAKeys(fileName="TestKey2")],
- "9dba0a1d-352d-4f46-bf05-aae7836add60",
- ForwardingTable(),
- Queue(),
- Contacts(),
- MessagesDB(),
- )
- User2Public = PublicUser(
- 2, "User2", [User2.encryptionKeys.publicKey, User2.signingKeys.publicKey], Circuit()
- )
- User1.contacts.addContact(User2Public)
- User2.contacts.addContact(User1Public)
- MSG = User1.createMessageToSent("Hello World!", User2.userName)
- ntwMSG = MSG.toNetworkMessage().asJSON().encode()
- intPacket = Packet(ntwMSG, User1.IP, User2.IP)
- intPacket.toNetworkLayer()
- toRead = []
- messagesReceived = WebSocketConnection()
- # Run messagesReceived.startreceive(toRead) in a separate thread.
- threading.Thread(target=messagesReceived.startreceive, args=(toRead,)).start()
- while True:
- if len(toRead) > 0:
- # Base64 decode the data.
- data = base64.b64decode(toRead.pop(0)).decode()
- cleanData = cleanData(data)
- MSG = User2.createMessageToReceive(cleanData)
- print(MSG.content)
- """
- $ node openWebSocket.js
- HTML
- $ python3 Simulation.py
- """
Add Comment
Please, Sign In to add comment