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:
parent
e8b855d37a
commit
8638b98179
1 changed files with 8 additions and 5 deletions
|
@ -1,5 +1,3 @@
|
|||
import ESock
|
||||
|
||||
BROADCAST = 0
|
||||
ROUTE = 1
|
||||
SOCK = 2
|
||||
|
@ -38,8 +36,6 @@ def create_routes(routes, handler):
|
|||
routes = routes.copy()
|
||||
reverse_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:
|
||||
routes[prefix] = routes[prefix][0](**routes[prefix][1])
|
||||
reverse_routes[routes[prefix]] = prefix
|
||||
|
@ -53,4 +49,11 @@ def create_routes(routes, handler):
|
|||
routes[prefix].route = reverse_routes[routes[prefix]]
|
||||
routes[prefix].PATCHED = True
|
||||
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
|
Reference in a new issue