-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python2 | ||
|
||
import IPy | ||
import json | ||
import pika | ||
import struct | ||
import time | ||
import os | ||
import socket | ||
import sys | ||
|
||
import setproctitle | ||
setproctitle.setproctitle('gatd-r: py-udp') | ||
|
||
sys.path.append(os.path.abspath('../config')) | ||
import gatdConfig | ||
|
||
addr_info = socket.getaddrinfo('::0', gatdConfig.receiver.PORT_UDP) | ||
|
||
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) | ||
s.bind(addr_info[0][-1]) | ||
|
||
amqp_conn = pika.BlockingConnection( | ||
pika.ConnectionParameters( | ||
host=gatdConfig.rabbitmq.HOST, | ||
port=gatdConfig.rabbitmq.PORT, | ||
credentials=pika.PlainCredentials( | ||
gatdConfig.rabbitmq.USERNAME, | ||
gatdConfig.rabbitmq.PASSWORD) | ||
)) | ||
amqp_chan = amqp_conn.channel(); | ||
|
||
while True: | ||
d, pkt_addr = s.recvfrom(1000) | ||
now = int(time.time()*1000) | ||
|
||
src_addr = pkt_addr[0] | ||
src_port = pkt_addr[1] | ||
|
||
# Get the IPv6 address in integer form | ||
try: | ||
addr = IPy.IP(IPy.IPint(src_addr)).v46map().int() | ||
except ValueError: | ||
# This was apparently already an IPv6 address | ||
addr = IPy.IPint(src_addr).int() | ||
|
||
|
||
amqp_pkt = struct.pack("!BQQHQ", | ||
gatdConfig.pkt.TYPE_UDP, | ||
addr>>(64*8), | ||
addr, | ||
src_port, | ||
now) | ||
|
||
amqp_pkt += d | ||
|
||
amqp_chan.basic_publish(exchange=gatdConfig.rabbitmq.XCH_RECEIVE, | ||
body=amqp_pkt, | ||
routing_key='') | ||
print(amqp_pkt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#!/bin/bash | ||
|
||
screen -S gatd-receiver-udp -m -d ./receiver-udp | ||
screen -S gatd-receiver-udp -m -d ./receiver-udp.py | ||
#screen -S gatd-receiver-udp -m -d ./receiver-udp | ||
screen -S gatd-receiver-tcp -m -d ./receiver_tcp.py | ||
screen -S gatd-receiver-http-post -m -d ./receiver_http_post.py |