Removed max route length and added route ids

Routes are now handled as numbers by the networking layer. This changes requires the first message to be a dict of all routes with their associated ids. This way only 2 bytes are used per message, not 16 like before.
This commit is contained in:
Philip Trauner 2016-09-11 20:32:13 +02:00
parent e8b855d37a
commit 8638b98179

View file

@ -1,5 +1,3 @@
import ESock
BROADCAST = 0 BROADCAST = 0
ROUTE = 1 ROUTE = 1
SOCK = 2 SOCK = 2
@ -38,8 +36,6 @@ def create_routes(routes, handler):
routes = routes.copy() routes = routes.copy()
reverse_routes = {} reverse_routes = {}
for prefix in routes: for prefix in routes:
if len(prefix) > ESock.MAX_ROUTE_LENGTH:
raise InvalidRouteLength("'%s' is too long (maximum: %d)" % (prefix, ESock.MAX_ROUTE_LENGTH))
if type(routes[prefix]) is tuple or type(routes[prefix]) is list: if type(routes[prefix]) is tuple or type(routes[prefix]) is list:
routes[prefix] = routes[prefix][0](**routes[prefix][1]) routes[prefix] = routes[prefix][0](**routes[prefix][1])
reverse_routes[routes[prefix]] = prefix reverse_routes[routes[prefix]] = prefix
@ -54,3 +50,10 @@ def create_routes(routes, handler):
routes[prefix].PATCHED = True routes[prefix].PATCHED = True
routes[prefix].start(handler) routes[prefix].start(handler)
return routes return routes
def create_exchange_map(routes):
exchange_map = {"meta" : -1}
for route in range(len(routes)):
exchange_map[route] = routes[route]
return exchange_map