Szymon Wróblewski avatar Szymon Wróblewski committed 61bc71c

inital commit

Comments (0)

Files changed (1)

ppenet/protocol.py

+from collections import namedtuple
+import socket
+from struct import Struct
+
+
+MINIMUM_MTU = 576
+MAXIMUM_MTU = 4096
+MAXIMUM_PACKET_COMMANDS = 32
+MINIMUM_WINDOW_SIZE = 4096
+MAXIMUM_WINDOW_SIZE = 32768
+MINIMUM_CHANNEL_COUNT = 1
+MAXIMUM_CHANNEL_COUNT = 255
+MAXIMUM_PEER_ID = 0xFFF
+MAXIMUM_PACKET_SIZE = 1024 * 1024 * 1024
+MAXIMUM_FRAGMENT_COUNT = 1024 * 1024
+
+class Command:
+    NONE, ACKNOWLEDGE, CONNECT, VERIFY_CONNECT, DISCONNECT, PING, \
+    SEND_RELIABLE, SEND_UNRELIABLE, SEND_FRAGMENT, SEND_UNSEQUENCED, \
+    BANDWIDTH_LIMIT, THROTTLE_CONFIGURE, SEND_UNRELIABLE_FRAGMENT, \
+    COUNT = range(14)
+
+
+class Flag:
+    COMMAND_FLAG_ACKNOWLEDGE = 1 << 7
+    COMMAND_FLAG_UNSEQUENCED = 1 << 6
+
+    HEADER_FLAG_COMPRESSED = 1 << 14
+    HEADER_FLAG_SENT_TIME  = 1 << 15
+    HEADER_FLAG_MASK       = HEADER_FLAG_COMPRESSED | HEADER_FLAG_SENT_TIME
+    HEADER_SESSION_MASK    = 3 << 12
+    HEADER_SESSION_SHIFT   = 12
+    
+
+Header = namedtuple('Header', (
+    'peerID',
+    'sentTime',
+))
+HeaderStruct = Struct('!HH')
+
+CommandHeader = namedtuple('CommandHeader', (
+    'command',
+    'channelID',
+    'reliableSequenceNumber',
+))
+CommandHeaderStruct = Struct('!BBH')
+
+Acknowledge = namedtuple('Acknowledge', (
+    'header',
+    'receivedReliableSequenceNumber',
+    'receivedSentTime'
+))
+AcknowledgeStruct = Struct('!%dsHH' % CommandHeaderStruct.size)
+
+Connect = namedtuple('Connect', (
+    'header',
+    'outgoingPeerID',
+    'incomingSessionID',
+    'outgoingSessionID',
+    'mtu',
+    'windowSize',
+    'channelCount',
+    'incomingBandwidth',
+    'outgoingBandwidth',
+    'packetThrottleInterval',
+    'packetThrottleAcceleration',
+    'packetThrottleDeceleration',
+    'connectID',
+    'data',
+))
+ConnectStruct = Struct('!%dsHBB10I' % CommandHeaderStruct.size)
+
+VerifyConnect = namedtuple('VerifyConnect', (
+    'header',
+    'outgoingPeerID',
+    'incomingSessionID',
+    'outgoingSessionID',
+    'mtu',
+    'windowSize',
+    'channelCount',
+    'incomingBandwidth',
+    'outgoingBandwidth',
+    'packetThrottleInterval',
+    'packetThrottleAcceleration',
+    'packetThrottleDeceleration',
+    'connectID',
+))
+VerifyConnectStruct = Struct('!%dsHBB9I' % CommandHeaderStruct.size)
+
+BandwidthLimit = namedtuple('BandwidthLimit', (
+    'header',
+    'incomingBandwidth',
+    'outgoingBandwidth',
+))
+BandwidthLimitStruct = Struct('!%dsII' % CommandHeaderStruct.size)
+
+ThrottleConfigure = namedtuple('ThrottleConfigure', (
+    'header',
+    'packetThrottleInterval',
+    'packetThrottleAcceleration',
+    'packetThrottleDeceleration',
+))
+ThrottleConfigureStruct = Struct('!%dsIII' % CommandHeaderStruct.size)
+
+Disconnect = namedtuple('Disconnect', (
+    'header',
+    'data',
+))
+DisconnectStruct = Struct('!%dsI' % CommandHeaderStruct.size)
+
+Ping = namedtuple('Ping', (
+    'header',
+))
+PingStruct = Struct('!%ds' % CommandHeaderStruct.size)
+
+SendReliable = namedtuple('SendReliable', (
+    'header',
+    'dataLength',
+))
+SendReliableStruct = Struct('!%dsH' % CommandHeaderStruct.size)
+
+SendUnreliable = namedtuple('SendUnreliable', (
+    'header',
+    'unreliableSequenceNumber',
+    'dataLength',
+))
+SendUnreliableStruct = Struct('!%dsHH' % CommandHeaderStruct.size)
+
+SendUnsequenced = namedtuple('SendUnsequenced', (
+    'header',
+    'unsequencedGroup',
+    'dataLength',
+))
+SendUnsequencedStruct = Struct('!%dsHH' % CommandHeaderStruct.size)
+
+SendFragment = namedtuple('SendFragment', (
+    'header',
+    'startSequenceNumber',
+    'dataLength',
+    'fragmentCount',
+    'fragmentNumber',
+    'totalLength',
+    'fragmentOffset',
+))
+SendFragmentStruct = Struct('!%dsHH4I' % CommandHeaderStruct.size)
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.