-
Notifications
You must be signed in to change notification settings - Fork 4
/
rpc_flood_client
executable file
·74 lines (55 loc) · 2.3 KB
/
rpc_flood_client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
import json
import uuid
import pika
import random
# RabbitMQ
node1 = pika.URLParameters('amqp://user:password@node1/')
node2 = pika.URLParameters('amqp://user:password@node2/')
node3 = pika.URLParameters('amqp://user:password@node3/')
all_endpoints = [node1, node2, node3]
#
# MAIN
#
def recv_callback(ch, method, properties, body):
#print ("Got Request:" + body)
request = json.loads(body)
channel.queue_delete(reply_name)
channel.exchange_delete(reply_name)
#json_string = json.dumps(data)
#channel.basic_publish(exchange=rabbitmq_exchange,
# routing_key=reply_fqdn,
# body=json_string)
#print(" [x] Sent " + json_string + " to " + reply_fqdn)
while True:
try:
random.shuffle(all_endpoints)
# RabbitMQ Connection
connection = pika.BlockingConnection(all_endpoints[0])
channel = connection.channel()
rabbitmq_exchange = 'rpc_flood'
while True:
reply_uuid = uuid.uuid4()
reply_name = 'rpc_flood_reply_' + str(reply_uuid)
# declare exchange
channel.exchange_declare(exchange=reply_name, exchange_type='direct', auto_delete=True)
# declare queue
result = channel.queue_declare(reply_name)
# bind routing-key <-> queue (use queue_name as routing_key)
channel.queue_bind(exchange=reply_name, queue=reply_name, routing_key=reply_name)
# send msg to control - it should answer to my routing key set
data = { 'routing_key': reply_name }
json_string = json.dumps(data)
channel.basic_consume(reply_name, recv_callback, auto_ack=True)
channel.basic_publish(exchange=rabbitmq_exchange, routing_key='control', body=json_string)
#print("Send %s data to %s exchange" % (json_string, rabbitmq_exchange))
#print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
# Do not recover on channel errors
except pika.exceptions.AMQPChannelError as err:
print("Caught a channel error: {}, stopping...".format(err))
break
# Recover on all other connection errors
except pika.exceptions.AMQPConnectionError:
print("Connection was closed, retrying...")
continue