-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,6 @@ asyncio | |
aio-udp-server | ||
pycryptodome | ||
msgpack | ||
coloredlogs | ||
coloredlogs | ||
pyzmq | ||
pymitter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
syntax = "proto2"; | ||
|
||
package scale; | ||
|
||
message Interface { | ||
required string name = 1; | ||
required string address = 2; | ||
required string mask = 3; | ||
required string broadcast = 4; | ||
required string gateway = 4; | ||
required string mac = 4; | ||
} | ||
|
||
message Join { | ||
required string hostname = 1; | ||
required int32 port = 2; | ||
repeated Interface interfaces = 3; | ||
} | ||
|
||
message Leave { | ||
required string hostname = 1; | ||
required int32 port = 2; | ||
} | ||
|
||
message NetworkMap { | ||
message Node { | ||
required string hostname = 1; | ||
required int32 port = 2; | ||
required boolean neighbor = 3; | ||
|
||
repeated Interface interfaces = 4; | ||
} | ||
|
||
repeated Node nodes = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import asyncio | ||
|
||
import zmq | ||
import zmq.asyncio | ||
from pymitter import EventEmitter | ||
|
||
|
||
class Coordinator: | ||
def __init__(self, loop: asyncio.AbstractEventLoop, event_bus: EventEmitter): | ||
self.loop = loop | ||
self.event_bus = event_bus | ||
|
||
def connect(self): | ||
self.context = zmq.asyncio.Context.instance() | ||
self.socket = self.context.socket(zmq.ROUTER) | ||
self.socket.bind(self.address) | ||
|
||
self.subscribe() | ||
|
||
def subscribe(self): | ||
self.loop.ensure_futures(self.handle_incoming(), self.loop) | ||
self.loop.ensure_futures(self.publish(), self.loop) | ||
|
||
async def handle_incoming(self,): | ||
msg = await self.sock.recv_multipart() | ||
# Decode protobuf | ||
print(msg) | ||
# Dispatch to listeners | ||
self.event_bus.emit('message.message_type', msg) | ||
|
||
async def send(self, reply): | ||
# Encode protobuf | ||
await self.socket.send_multipart(reply) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters