Wait for one of the messages in the list
(self, *message_classes)
| 386 | return envelope |
| 387 | |
| 388 | def wait_for(self, *message_classes): |
| 389 | '''Wait for one of the messages in the list''' |
| 390 | # initialize the command we have, which should be None |
| 391 | command = None |
| 392 | command_to_class = {m.command: m for m in message_classes} |
| 393 | # loop until the command is in the commands we want |
| 394 | while command not in command_to_class.keys(): |
| 395 | # get the next network message |
| 396 | envelope = self.read() |
| 397 | # set the command to be evaluated |
| 398 | command = envelope.command |
| 399 | # we know how to respond to version and ping, handle that here |
| 400 | if command == VersionMessage.command: |
| 401 | # send verack |
| 402 | self.send(VerAckMessage()) |
| 403 | elif command == PingMessage.command: |
| 404 | # send pong |
| 405 | self.send(PongMessage(envelope.payload)) |
| 406 | # return the envelope parsed as a member of the right message class |
| 407 | return command_to_class[command].parse(envelope.stream()) |
| 408 | |
| 409 | |
| 410 | class SimpleNodeTest(TestCase): |
no test coverage detected