more work
This commit is contained in:
parent
2cdddd4515
commit
0d6c39900b
3 changed files with 241 additions and 79 deletions
|
@ -71,53 +71,16 @@ import threading
|
|||
import socket
|
||||
import logging
|
||||
import struct
|
||||
import errno
|
||||
import encrypt
|
||||
import eventloop
|
||||
import lru_cache
|
||||
import errno
|
||||
from common import parse_header
|
||||
|
||||
|
||||
BUF_SIZE = 65536
|
||||
|
||||
|
||||
def parse_header(data):
|
||||
addrtype = ord(data[0])
|
||||
dest_addr = None
|
||||
dest_port = None
|
||||
header_length = 0
|
||||
if addrtype == 1:
|
||||
if len(data) >= 7:
|
||||
dest_addr = socket.inet_ntoa(data[1:5])
|
||||
dest_port = struct.unpack('>H', data[5:7])[0]
|
||||
header_length = 7
|
||||
else:
|
||||
logging.warn('[udp] header is too short')
|
||||
elif addrtype == 3:
|
||||
if len(data) > 2:
|
||||
addrlen = ord(data[1])
|
||||
if len(data) >= 2 + addrlen:
|
||||
dest_addr = data[2:2 + addrlen]
|
||||
dest_port = struct.unpack('>H', data[2 + addrlen:4 +
|
||||
addrlen])[0]
|
||||
header_length = 4 + addrlen
|
||||
else:
|
||||
logging.warn('[udp] header is too short')
|
||||
else:
|
||||
logging.warn('[udp] header is too short')
|
||||
elif addrtype == 4:
|
||||
if len(data) >= 19:
|
||||
dest_addr = socket.inet_ntop(socket.AF_INET6, data[1:17])
|
||||
dest_port = struct.unpack('>H', data[17:19])[0]
|
||||
header_length = 19
|
||||
else:
|
||||
logging.warn('[udp] header is too short')
|
||||
else:
|
||||
logging.warn('unsupported addrtype %d' % addrtype)
|
||||
if dest_addr is None:
|
||||
return None
|
||||
return (addrtype, dest_addr, dest_port, header_length)
|
||||
|
||||
|
||||
def client_key(a, b, c, d):
|
||||
return '%s:%s:%s:%s' % (a, b, c, d)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue