2019-01-25 14:40:31 +01:00
|
|
|
import zmq
|
2019-02-04 13:53:38 +01:00
|
|
|
# from zmq.asyncio import Context, ZMQEventLoop
|
|
|
|
# import asyncio
|
2019-01-25 17:02:04 +01:00
|
|
|
from enum import Enum, auto
|
2019-01-25 14:40:31 +01:00
|
|
|
|
|
|
|
class Role(Enum):
|
2019-01-25 17:02:04 +01:00
|
|
|
NONE = 'NONE'
|
|
|
|
SERVER = 'SERVER'
|
|
|
|
CLIENT = 'CLIENT'
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.value
|
2019-01-25 14:40:31 +01:00
|
|
|
|
|
|
|
class Replication(Enum):
|
2019-01-25 17:02:04 +01:00
|
|
|
NONE = auto()
|
|
|
|
REPLICATED = auto()
|
|
|
|
REPNOTIFY = auto()
|
2019-01-25 10:11:40 +01:00
|
|
|
|
|
|
|
class User:
|
2019-01-25 14:40:31 +01:00
|
|
|
def __init__(self, name="default", ip="localhost",role=Role.NONE):
|
2019-01-25 10:11:40 +01:00
|
|
|
self.name = name
|
2019-01-25 14:40:31 +01:00
|
|
|
self.role = role
|
2019-01-25 10:11:40 +01:00
|
|
|
|
2019-01-25 14:40:31 +01:00
|
|
|
class NetworkInterface:
|
2019-02-04 13:53:38 +01:00
|
|
|
def __init__(self, host="*",context=None, socket_type=zmq.REQ,protocol='tcp',port=5555):
|
2019-01-25 10:11:40 +01:00
|
|
|
self.host = host
|
2019-01-25 14:40:31 +01:00
|
|
|
self.context = context
|
|
|
|
self.socket = context.socket(socket_type)
|
2019-01-25 17:28:53 +01:00
|
|
|
self.poller = zmq.Poller()
|
|
|
|
|
2019-01-25 14:40:31 +01:00
|
|
|
#TODO: Is this right to it here?
|
2019-01-25 17:28:53 +01:00
|
|
|
self.poller.register(self.socket, zmq.POLLIN)
|
2019-02-04 13:53:38 +01:00
|
|
|
print("{}://{}:{}".format(protocol,host,port))
|
|
|
|
self.socket.bind("tcp://*:5555")
|
2019-01-25 10:11:40 +01:00
|
|
|
|
|
|
|
class Property:
|
2019-01-25 14:40:31 +01:00
|
|
|
def __init__(self, property=None, replication=Replication.NONE):
|
2019-01-25 10:11:40 +01:00
|
|
|
self.property = property
|
2019-01-25 14:40:31 +01:00
|
|
|
self.replication = replication
|
2019-01-25 10:11:40 +01:00
|
|
|
|
|
|
|
class Function:
|
|
|
|
def __init__(self, function=None):
|
2019-01-25 14:40:31 +01:00
|
|
|
self.function = function
|
|
|
|
|