Commit c8dabbff authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove 'address' argument from AcceptIdentification packet.

This argument is useless as the peer who receive this packet is the one who starts the connection, so it already knows the peer remote address.
Remove related (useless) checks and update unit tests.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1521 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 6445101c
...@@ -109,7 +109,7 @@ class BootstrapManager(EventHandler): ...@@ -109,7 +109,7 @@ class BootstrapManager(EventHandler):
self.uuid, self.server, self.name)) self.uuid, self.server, self.name))
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, num_partitions, num_replicas, your_uuid):
""" """
The primary master has accepted the node. The primary master has accepted the node.
""" """
......
...@@ -31,21 +31,13 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -31,21 +31,13 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
app.setNodeNotReady() app.setNodeNotReady()
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, num_partitions, num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
# this must be a master node # this must be a master node
if node_type != NodeTypes.MASTER: if node_type != NodeTypes.MASTER:
conn.close() conn.close()
return return
if conn.getAddress() != address:
# The server address is different! Then why was
# the connection successful?
logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], *address)
app.nm.remove(node)
conn.close()
return
conn.setUUID(uuid) conn.setUUID(uuid)
node.setUUID(uuid) node.setUUID(uuid)
......
...@@ -53,21 +53,13 @@ class StorageBootstrapHandler(AnswerBaseHandler): ...@@ -53,21 +53,13 @@ class StorageBootstrapHandler(AnswerBaseHandler):
app.setNodeNotReady() app.setNodeNotReady()
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, num_partitions, num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
# this must be a storage node # this must be a storage node
if node_type != NodeTypes.STORAGE: if node_type != NodeTypes.STORAGE:
conn.close() conn.close()
return return
if conn.getAddress() != address:
# The server address is different! Then why was
# the connection successful?
logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], *address)
app.nm.remove(node)
conn.close()
return
conn.setUUID(uuid) conn.setUUID(uuid)
node.setUUID(uuid) node.setUUID(uuid)
......
...@@ -142,11 +142,11 @@ class EventHandler(object): ...@@ -142,11 +142,11 @@ class EventHandler(object):
# Packet handlers. # Packet handlers.
def requestIdentification(self, conn, packet, node_type, def requestIdentification(self, conn, packet, node_type,
uuid, address, name): uuid, name):
raise UnexpectedPacketError raise UnexpectedPacketError
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, num_partitions, num_replicas, your_uuid):
raise UnexpectedPacketError raise UnexpectedPacketError
def askPrimary(self, conn, packet): def askPrimary(self, conn, packet):
......
...@@ -60,7 +60,7 @@ class PacketLogger(EventHandler): ...@@ -60,7 +60,7 @@ class PacketLogger(EventHandler):
pass pass
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, num_partitions, num_replicas, your_uuid):
pass pass
def askPrimary(self, conn, packet): def askPrimary(self, conn, packet):
......
...@@ -111,22 +111,12 @@ class ClientElectionHandler(ElectionHandler): ...@@ -111,22 +111,12 @@ class ClientElectionHandler(ElectionHandler):
MasterHandler.peerBroken(self, conn) MasterHandler.peerBroken(self, conn)
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, uuid, num_partitions, num_replicas, your_uuid):
num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
if node_type != NodeTypes.MASTER: if node_type != NodeTypes.MASTER:
# The peer is not a master node! # The peer is not a master node!
logging.error('%s:%d is not a master node', *address) logging.error('%s:%d is not a master node', conn.getAddress())
app.nm.remove(node)
app.negotiating_master_node_set.discard(node.getAddress())
conn.close()
return
if conn.getAddress() != address:
# The server address is different! Then why was
# the connection successful?
logging.error('%s:%d is waiting for %s:%d',
conn.getAddress()[0], conn.getAddress()[1], *address)
app.nm.remove(node) app.nm.remove(node)
app.negotiating_master_node_set.discard(node.getAddress()) app.negotiating_master_node_set.discard(node.getAddress())
conn.close() conn.close()
...@@ -250,7 +240,6 @@ class ServerElectionHandler(ElectionHandler): ...@@ -250,7 +240,6 @@ class ServerElectionHandler(ElectionHandler):
p = Packets.AcceptIdentification( p = Packets.AcceptIdentification(
NodeTypes.MASTER, NodeTypes.MASTER,
app.uuid, app.uuid,
app.server,
app.pt.getPartitions(), app.pt.getPartitions(),
app.pt.getReplicas(), app.pt.getReplicas(),
uuid uuid
......
...@@ -75,8 +75,8 @@ class IdentificationHandler(MasterHandler): ...@@ -75,8 +75,8 @@ class IdentificationHandler(MasterHandler):
conn.setUUID(uuid) conn.setUUID(uuid)
conn.setHandler(handler) conn.setHandler(handler)
# answer # answer
args = (NodeTypes.MASTER, app.uuid, app.server, args = (NodeTypes.MASTER, app.uuid, app.pt.getPartitions(),
app.pt.getPartitions(), app.pt.getReplicas(), uuid) app.pt.getReplicas(), uuid)
conn.answer(Packets.AcceptIdentification(*args), packet.getId()) conn.answer(Packets.AcceptIdentification(*args), packet.getId())
# trigger the event # trigger the event
handler.connectionCompleted(conn) handler.connectionCompleted(conn)
......
...@@ -84,12 +84,11 @@ class PrimaryHandler(MasterHandler): ...@@ -84,12 +84,11 @@ class PrimaryHandler(MasterHandler):
n.setUUID(uuid) n.setUUID(uuid)
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, uuid, num_partitions,
num_replicas, your_uuid): num_replicas, your_uuid):
app = self.app app = self.app
node = app.nm.getByAddress(conn.getAddress()) node = app.nm.getByAddress(conn.getAddress())
assert node_type == NodeTypes.MASTER assert node_type == NodeTypes.MASTER
assert conn.getAddress() == address
if your_uuid != app.uuid: if your_uuid != app.uuid:
# uuid conflict happened, accept the new one # uuid conflict happened, accept the new one
......
...@@ -321,23 +321,20 @@ class AcceptIdentification(Packet): ...@@ -321,23 +321,20 @@ class AcceptIdentification(Packet):
Accept a node identification. This should be a reply to Request Node Accept a node identification. This should be a reply to Request Node
Identification. Any -> Any. Identification. Any -> Any.
""" """
def _encode(self, node_type, uuid, address, def _encode(self, node_type, uuid,
num_partitions, num_replicas, your_uuid): num_partitions, num_replicas, your_uuid):
uuid = _encodeUUID(uuid) uuid = _encodeUUID(uuid)
your_uuid = _encodeUUID(your_uuid) your_uuid = _encodeUUID(your_uuid)
address = _encodeAddress(address) return pack('!H16sLL16s', node_type, uuid,
return pack('!H16s6sLL16s', node_type, uuid, address,
num_partitions, num_replicas, your_uuid) num_partitions, num_replicas, your_uuid)
def _decode(self, body): def _decode(self, body):
r = unpack('!H16s6sLL16s', body) r = unpack('!H16sLL16s', body)
node_type, uuid, address, num_partitions, num_replicas, your_uuid = r node_type, uuid, num_partitions, num_replicas, your_uuid = r
address = _decodeAddress(address)
node_type = _decodeNodeType(node_type) node_type = _decodeNodeType(node_type)
uuid = _decodeUUID(uuid) uuid = _decodeUUID(uuid)
your_uuid == _decodeUUID(uuid) your_uuid == _decodeUUID(uuid)
return (node_type, uuid, address, num_partitions, num_replicas, return (node_type, uuid, num_partitions, num_replicas, your_uuid)
your_uuid)
class AskPrimary(Packet): class AskPrimary(Packet):
""" """
......
...@@ -47,7 +47,7 @@ class HiddenHandler(BaseMasterHandler): ...@@ -47,7 +47,7 @@ class HiddenHandler(BaseMasterHandler):
pass pass
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, num_partitions, num_replicas, your_uuid):
pass pass
def answerPrimary(self, conn, packet, primary_uuid, def answerPrimary(self, conn, packet, primary_uuid,
......
...@@ -58,8 +58,8 @@ class IdentificationHandler(BaseStorageHandler): ...@@ -58,8 +58,8 @@ class IdentificationHandler(BaseStorageHandler):
conn.setHandler(handler) conn.setHandler(handler)
conn.setUUID(uuid) conn.setUUID(uuid)
node.setUUID(uuid) node.setUUID(uuid)
args = (NodeTypes.STORAGE, app.uuid, app.server, args = (NodeTypes.STORAGE, app.uuid, app.pt.getPartitions(),
app.pt.getPartitions(), app.pt.getReplicas(), uuid) app.pt.getReplicas(), uuid)
# accept the identification and trigger an event # accept the identification and trigger an event
conn.answer(Packets.AcceptIdentification(*args), packet.getId()) conn.answer(Packets.AcceptIdentification(*args), packet.getId())
handler.connectionCompleted(conn) handler.connectionCompleted(conn)
......
...@@ -37,7 +37,7 @@ class ReplicationHandler(BaseStorageHandler): ...@@ -37,7 +37,7 @@ class ReplicationHandler(BaseStorageHandler):
self.app.replicator.reset() self.app.replicator.reset()
def acceptIdentification(self, conn, packet, node_type, def acceptIdentification(self, conn, packet, node_type,
uuid, address, num_partitions, num_replicas, your_uuid): uuid, num_partitions, num_replicas, your_uuid):
# set the UUID on the connection # set the UUID on the connection
conn.setUUID(uuid) conn.setUUID(uuid)
......
...@@ -84,12 +84,10 @@ class ProtocolTests(NeoTestBase): ...@@ -84,12 +84,10 @@ class ProtocolTests(NeoTestBase):
def test_12_AcceptIdentification(self): def test_12_AcceptIdentification(self):
uuid1, uuid2 = self.getNewUUID(), self.getNewUUID() uuid1, uuid2 = self.getNewUUID(), self.getNewUUID()
p = Packets.AcceptIdentification(NodeTypes.CLIENT, uuid1, p = Packets.AcceptIdentification(NodeTypes.CLIENT, uuid1,
("127.0.0.1", 9080), 10, 20, uuid2) 10, 20, uuid2)
node, p_uuid, (ip, port), nb_partitions, nb_replicas, your_uuid = p.decode() node, p_uuid, nb_partitions, nb_replicas, your_uuid = p.decode()
self.assertEqual(node, NodeTypes.CLIENT) self.assertEqual(node, NodeTypes.CLIENT)
self.assertEqual(p_uuid, uuid1) self.assertEqual(p_uuid, uuid1)
self.assertEqual(ip, "127.0.0.1")
self.assertEqual(port, 9080)
self.assertEqual(nb_partitions, 10) self.assertEqual(nb_partitions, 10)
self.assertEqual(nb_replicas, 20) self.assertEqual(nb_replicas, 20)
self.assertEqual(your_uuid, uuid2) self.assertEqual(your_uuid, uuid2)
......
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