Commit a3497ce2 authored by Vincent Pelletier's avatar Vincent Pelletier

Add 2 new packet types: ASK_NODE_INFORMATION and ANSWER_NODE_INFORMATION.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@664 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 3774858d
...@@ -41,7 +41,7 @@ from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICAT ...@@ -41,7 +41,7 @@ from protocol import ERROR, REQUEST_NODE_IDENTIFICATION, ACCEPT_NODE_IDENTIFICAT
PROTOCOL_ERROR_CODE, TIMEOUT_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \ PROTOCOL_ERROR_CODE, TIMEOUT_ERROR_CODE, BROKEN_NODE_DISALLOWED_CODE, \
INTERNAL_ERROR_CODE, ASK_PARTITION_LIST, ANSWER_PARTITION_LIST, ASK_NODE_LIST, \ INTERNAL_ERROR_CODE, ASK_PARTITION_LIST, ANSWER_PARTITION_LIST, ASK_NODE_LIST, \
ANSWER_NODE_LIST, SET_NODE_STATE, ANSWER_NODE_STATE, SET_CLUSTER_STATE, \ ANSWER_NODE_LIST, SET_NODE_STATE, ANSWER_NODE_STATE, SET_CLUSTER_STATE, \
ANSWER_CLUSTER_STATE ANSWER_CLUSTER_STATE, ASK_NODE_INFORMATION, ANSWER_NODE_INFORMATION
# Some decorators useful to avoid duplication of patterns in handlers # Some decorators useful to avoid duplication of patterns in handlers
...@@ -394,6 +394,11 @@ class EventHandler(object): ...@@ -394,6 +394,11 @@ class EventHandler(object):
def handleAnswerClusterState(self, conn, packet, state): def handleAnswerClusterState(self, conn, packet, state):
raise UnexpectedPacketError raise UnexpectedPacketError
def handleAskNodeInformation(self, conn, packet):
raise UnexpectedPacketError
def handleAnswerNodeInformation(self, conn, packet, node_list):
raise UnexpectedPacketError
# Error packet handlers. # Error packet handlers.
...@@ -478,6 +483,8 @@ class EventHandler(object): ...@@ -478,6 +483,8 @@ class EventHandler(object):
d[ANSWER_CLUSTER_STATE] = self.handleAnswerClusterState d[ANSWER_CLUSTER_STATE] = self.handleAnswerClusterState
d[ADD_PENDING_NODES] = self.handleAddPendingNodes d[ADD_PENDING_NODES] = self.handleAddPendingNodes
d[ANSWER_NEW_NODES] = self.handleAnswerNewNodes d[ANSWER_NEW_NODES] = self.handleAnswerNewNodes
d[ASK_NODE_INFORMATION] = self.handleAskNodeInformation
d[ANSWER_NODE_INFORMATION] = self.handleAnswerNodeInformation
self.packet_dispatch_table = d self.packet_dispatch_table = d
......
...@@ -293,6 +293,12 @@ packet_types = Enum({ ...@@ -293,6 +293,12 @@ packet_types = Enum({
# Anwer what are the nodes added in the partition table # Anwer what are the nodes added in the partition table
'ANSWER_NEW_NODES': 0x8025, 'ANSWER_NEW_NODES': 0x8025,
# Ask node information
'ASK_NODE_INFORMATION': 0x0026,
# Answer node information
'ANSWER_NODE_INFORMATION': 0x8026,
}) })
# Error codes. # Error codes.
...@@ -963,6 +969,10 @@ def _decodeAnswerNewNodes(body): ...@@ -963,6 +969,10 @@ def _decodeAnswerNewNodes(body):
return (uuid_list, ) return (uuid_list, )
decode_table[ANSWER_NEW_NODES] = _decodeAnswerNewNodes decode_table[ANSWER_NEW_NODES] = _decodeAnswerNewNodes
def _decodeAskNodeInformation(body):
pass # No payload
decode_table[ASK_NODE_INFORMATION] = _decodeAskNodeInformation
decode_table[ANSWER_NODE_INFORMATION] = _decodeNotifyNodeInformation
# Packet encoding # Packet encoding
...@@ -1270,3 +1280,16 @@ def answerNewNodes(uuid_list): ...@@ -1270,3 +1280,16 @@ def answerNewNodes(uuid_list):
uuid_list = [pack('!16s', uuid) for uuid in uuid_list] uuid_list = [pack('!16s', uuid) for uuid in uuid_list]
body = pack('!H', len(uuid_list)) + ''.join(uuid_list) body = pack('!H', len(uuid_list)) + ''.join(uuid_list)
return Packet(ANSWER_NEW_NODES, body) return Packet(ANSWER_NEW_NODES, body)
def askNodeInformation():
return Packet(ASK_NODE_INFORMATION)
def answerNodeInformation(node_list):
# XXX: copy-paste from notifyNodeInformation
body = [pack('!L', len(node_list))]
for node_type, ip_address, port, uuid, state in node_list:
body.append(pack('!H4sH16sH', node_type, inet_aton(ip_address), port,
uuid, state))
body = ''.join(body)
return Packet(ANSWER_NODE_INFORMATION, body)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment