pyrak 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyrak-0.1.0/LICENSE ADDED
@@ -0,0 +1,207 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and
10
+ distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by the
13
+ copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other
16
+ entities that control, are controlled by, or are under common control with
17
+ that entity. For the purposes of this definition, "control" means (i) the
18
+ power, direct or indirect, to cause the direction or management of such
19
+ entity, whether by contract or otherwise, or (ii) ownership of
20
+ fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
21
+ ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity exercising
24
+ permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation source,
28
+ and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical transformation
31
+ or translation of a Source form, including but not limited to compiled
32
+ object code, generated documentation, and conversions to
33
+ other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or Object
36
+ form, made available under the License, as indicated by a copyright notice
37
+ that is included in or attached to the work (an example is provided in the
38
+ Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object form,
41
+ that is based on (or derived from) the Work and for which the editorial
42
+ revisions, annotations, elaborations, or other modifications represent,
43
+ as a whole, an original work of authorship. For the purposes of this
44
+ License, Derivative Works shall not include works that remain separable
45
+ from, or merely link (or bind by name) to the interfaces of, the Work and
46
+ Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including the original
49
+ version of the Work and any modifications or additions to that Work or
50
+ Derivative Works thereof, that is intentionally submitted to Licensor for
51
+ inclusion in the Work by the copyright owner or by an individual or
52
+ Legal Entity authorized to submit on behalf of the copyright owner.
53
+ For the purposes of this definition, "submitted" means any form of
54
+ electronic, verbal, or written communication sent to the Licensor or its
55
+ representatives, including but not limited to communication on electronic
56
+ mailing lists, source code control systems, and issue tracking systems
57
+ that are managed by, or on behalf of, the Licensor for the purpose of
58
+ discussing and improving the Work, but excluding communication that is
59
+ conspicuously marked or otherwise designated in writing by the copyright
60
+ owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity on
63
+ behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License.
67
+
68
+ Subject to the terms and conditions of this License, each Contributor
69
+ hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
70
+ royalty-free, irrevocable copyright license to reproduce, prepare
71
+ Derivative Works of, publicly display, publicly perform, sublicense,
72
+ and distribute the Work and such Derivative Works in
73
+ Source or Object form.
74
+
75
+ 3. Grant of Patent License.
76
+
77
+ Subject to the terms and conditions of this License, each Contributor
78
+ hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
79
+ royalty-free, irrevocable (except as stated in this section) patent
80
+ license to make, have made, use, offer to sell, sell, import, and
81
+ otherwise transfer the Work, where such license applies only to those
82
+ patent claims licensable by such Contributor that are necessarily
83
+ infringed by their Contribution(s) alone or by combination of their
84
+ Contribution(s) with the Work to which such Contribution(s) was submitted.
85
+ If You institute patent litigation against any entity (including a
86
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
87
+ Contribution incorporated within the Work constitutes direct or
88
+ contributory patent infringement, then any patent licenses granted to
89
+ You under this License for that Work shall terminate as of the date such
90
+ litigation is filed.
91
+
92
+ 4. Redistribution.
93
+
94
+ You may reproduce and distribute copies of the Work or Derivative Works
95
+ thereof in any medium, with or without modifications, and in Source or
96
+ Object form, provided that You meet the following conditions:
97
+
98
+ 1. You must give any other recipients of the Work or Derivative Works a
99
+ copy of this License; and
100
+
101
+ 2. You must cause any modified files to carry prominent notices stating
102
+ that You changed the files; and
103
+
104
+ 3. You must retain, in the Source form of any Derivative Works that You
105
+ distribute, all copyright, patent, trademark, and attribution notices from
106
+ the Source form of the Work, excluding those notices that do not pertain
107
+ to any part of the Derivative Works; and
108
+
109
+ 4. If the Work includes a "NOTICE" text file as part of its distribution,
110
+ then any Derivative Works that You distribute must include a readable copy
111
+ of the attribution notices contained within such NOTICE file, excluding
112
+ those notices that do not pertain to any part of the Derivative Works,
113
+ in at least one of the following places: within a NOTICE text file
114
+ distributed as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or, within a
116
+ display generated by the Derivative Works, if and wherever such
117
+ third-party notices normally appear. The contents of the NOTICE file are
118
+ for informational purposes only and do not modify the License.
119
+ You may add Your own attribution notices within Derivative Works that You
120
+ distribute, alongside or as an addendum to the NOTICE text from the Work,
121
+ provided that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and may
125
+ provide additional or different license terms and conditions for use,
126
+ reproduction, or distribution of Your modifications, or for any such
127
+ Derivative Works as a whole, provided Your use, reproduction, and
128
+ distribution of the Work otherwise complies with the conditions
129
+ stated in this License.
130
+
131
+ 5. Submission of Contributions.
132
+
133
+ Unless You explicitly state otherwise, any Contribution intentionally
134
+ submitted for inclusion in the Work by You to the Licensor shall be under
135
+ the terms and conditions of this License, without any additional
136
+ terms or conditions. Notwithstanding the above, nothing herein shall
137
+ supersede or modify the terms of any separate license agreement you may
138
+ have executed with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks.
141
+
142
+ This License does not grant permission to use the trade names, trademarks,
143
+ service marks, or product names of the Licensor, except as required for
144
+ reasonable and customary use in describing the origin of the Work and
145
+ reproducing the content of the NOTICE file.
146
+
147
+ 7. Disclaimer of Warranty.
148
+
149
+ Unless required by applicable law or agreed to in writing, Licensor
150
+ provides the Work (and each Contributor provides its Contributions)
151
+ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
152
+ either express or implied, including, without limitation, any warranties
153
+ or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS
154
+ FOR A PARTICULAR PURPOSE. You are solely responsible for determining the
155
+ appropriateness of using or redistributing the Work and assume any risks
156
+ associated with Your exercise of permissions under this License.
157
+
158
+ 8. Limitation of Liability.
159
+
160
+ In no event and under no legal theory, whether in tort
161
+ (including negligence), contract, or otherwise, unless required by
162
+ applicable law (such as deliberate and grossly negligent acts) or agreed
163
+ to in writing, shall any Contributor be liable to You for damages,
164
+ including any direct, indirect, special, incidental, or consequential
165
+ damages of any character arising as a result of this License or out of
166
+ the use or inability to use the Work (including but not limited to damages
167
+ for loss of goodwill, work stoppage, computer failure or malfunction,
168
+ or any and all other commercial damages or losses), even if such
169
+ Contributor has been advised of the possibility of such damages.
170
+
171
+ 9. Accepting Warranty or Additional Liability.
172
+
173
+ While redistributing the Work or Derivative Works thereof, You may choose
174
+ to offer, and charge a fee for, acceptance of support, warranty,
175
+ indemnity, or other liability obligations and/or rights consistent with
176
+ this License. However, in accepting such obligations, You may act only
177
+ on Your own behalf and on Your sole responsibility, not on behalf of any
178
+ other Contributor, and only if You agree to indemnify, defend, and hold
179
+ each Contributor harmless for any liability incurred by, or claims
180
+ asserted against, such Contributor by reason of your accepting any such
181
+ warranty or additional liability.
182
+
183
+ END OF TERMS AND CONDITIONS
184
+
185
+ APPENDIX: How to apply the Apache License to your work
186
+
187
+ To apply the Apache License to your work, attach the following boilerplate
188
+ notice, with the fields enclosed by brackets "[]" replaced with your own
189
+ identifying information. (Don't include the brackets!) The text should be
190
+ enclosed in the appropriate comment syntax for the file format. We also
191
+ recommend that a file or class name and description of purpose be included
192
+ on the same "printed page" as the copyright notice for easier
193
+ identification within third-party archives.
194
+
195
+ Copyright 2026 loudblow
196
+
197
+ Licensed under the Apache License, Version 2.0 (the "License");
198
+ you may not use this file except in compliance with the License.
199
+ You may obtain a copy of the License at
200
+
201
+ http://www.apache.org/licenses/LICENSE-2.0
202
+
203
+ Unless required by applicable law or agreed to in writing, software
204
+ distributed under the License is distributed on an "AS IS" BASIS,
205
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
206
+ or implied. See the License for the specific language governing
207
+ permissions and limitations under the License.
pyrak-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyrak
3
+ Version: 0.1.0
4
+ Summary: An async implementation of the RakNet protocol
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Author: loudblow
8
+ Author-email: 145815114+loudblow@users.noreply.github.com
9
+ Requires-Python: >=3.11
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Requires-Dist: anyio (>=4.12.1,<5.0.0)
16
+ Requires-Dist: rombob (>=1.1.0,<2.0.0)
17
+ Project-URL: Source, https://github.com/loudblow/pyrak/
18
+ Description-Content-Type: text/markdown
19
+
20
+ # pyrak
21
+
22
+ An async implementation of the [RakNet](https://github.com/facebookarchive/RakNet) protocol in pure Python.
23
+ Built on [anyio](https://anyio.readthedocs.io/) (works with both asyncio and trio). A single `RakPeer` can act
24
+ as a client, a server, or both at once.
25
+
26
+ > Status: MVP. Verified against a real MCPE client (see [TODO.md](TODO.md)).
27
+
28
+ ## Features
29
+
30
+ - Offline handshake and connection: `OpenConnectionRequest1/2`, `ConnectionRequest`, `NewIncomingConnection`,
31
+ MTU negotiation, protocol version check, IP bans
32
+ - All reliability modes: `UNRELIABLE`, `UNRELIABLE_SEQUENCED`, `RELIABLE`, `RELIABLE_ORDERED`, `RELIABLE_SEQUENCED`
33
+ - Ordering channels, send priorities, splitting of large messages, ACK/NAK and retransmission
34
+ - Connected/unconnected ping (RTT, and MOTD via `UnconnectedPong`), timeouts and graceful disconnect
35
+ - Declarative wire types on [rombob](https://pypi.org/project/rombob/); your own messages are carried as `UserMessage`
36
+ - `ReliabilityLayer` has no sockets and no clock (time is passed in), so it is easy to test
37
+
38
+ Not implemented yet: congestion control, security/cookie handshake, ack receipts, NAT punchthrough.
39
+
40
+ ## Installation
41
+
42
+ Requires Python 3.11+.
43
+
44
+ ```bash
45
+ pip install pyrak
46
+ ```
47
+
48
+ Or install the latest unreleased code straight from Git:
49
+
50
+ ```bash
51
+ pip install git+https://github.com/loudblow/rombob.git@main
52
+ ```
53
+
54
+
55
+ The `rombob` dependency is pulled from a GitHub release.
56
+
57
+ ## Server
58
+
59
+ ```python
60
+ import anyio
61
+
62
+ from pyrak import (
63
+ RELIABLE_ORDERED,
64
+ ConnectionLost,
65
+ DisconnectionNotification,
66
+ NewIncomingConnection,
67
+ RakPeer,
68
+ UserMessage,
69
+ )
70
+
71
+
72
+ async def main() -> None:
73
+ async with RakPeer(max_connections=10, max_incoming_connections=10) as server:
74
+ server.payload = "MCPE;pyrak;122;;0;10;0;hello;Creative;1;19132;19133;" # MOTD
75
+ await server.listen(("0.0.0.0", 19132))
76
+
77
+ async for packet in server: # packet.address, packet.guid, packet.message
78
+ match packet.message:
79
+ case NewIncomingConnection():
80
+ print(f"{packet.address} connected")
81
+ case UserMessage(id=0x86, payload=data):
82
+ # echo back to the same client
83
+ await server.send(
84
+ packet.guid, UserMessage(0x87, data), RELIABLE_ORDERED
85
+ )
86
+ case DisconnectionNotification() | ConnectionLost():
87
+ print(f"{packet.address} left")
88
+
89
+
90
+ anyio.run(main)
91
+ ```
92
+
93
+ [`examples/mcpe_server.py`](examples/mcpe_server.py) is a server that shows up in the server list of a real
94
+ Minecraft PE client and receives its first game packet (`0xFE`):
95
+
96
+ ```bash
97
+ poetry run python examples/mcpe_server.py 19132
98
+ ```
99
+
100
+ ## Client
101
+
102
+ ```python
103
+ import anyio
104
+
105
+ from pyrak import RELIABLE_ORDERED, RakPeer, UserMessage
106
+
107
+
108
+ async def main() -> None:
109
+ async with RakPeer(max_connections=1) as client:
110
+ server = ("127.0.0.1", 19132)
111
+
112
+ # unconnected ping: fetch the server's MOTD
113
+ pong = await client.ping(server)
114
+ print("MOTD:", pong.payload if pong else "no answer")
115
+
116
+ session = await client.connect(server) # waits for the handshake
117
+ print("RTT, ms:", await client.ping(server, connected=True))
118
+
119
+ await client.send(server, UserMessage(0x86, b"hello"), RELIABLE_ORDERED)
120
+ # or raw bytes: the first byte is the message id
121
+ await client.send(server, b"\x86hello", RELIABLE_ORDERED, channel=1)
122
+
123
+ packet = await client.receive()
124
+ print(packet.message)
125
+
126
+ await client.disconnect(session)
127
+
128
+
129
+ anyio.run(main)
130
+ ```
131
+
132
+ Connection failures (`ConnectionBannedError`, `IncompatibleProtocolVersionError`,
133
+ `NoFreeIncomingConnectionsError`, `AlreadyConnectedError`, ...) are defined in `pyrak.errors`.
134
+
135
+ ## Management
136
+
137
+ ```python
138
+ server.ban("1.2.3.4", duration=60_000) # ban for 60 seconds (0 = permanent)
139
+ server.unban("1.2.3.4")
140
+ server.sessions # active sessions
141
+ await server.disconnect(packet.guid) # close a session gracefully
142
+ await server.shutdown(block_duration=500)
143
+ ```
144
+
145
+ ## Development
146
+
147
+ ```bash
148
+ make install # set up the environment
149
+ make test # tests with coverage
150
+ make lint # ruff via pre-commit
151
+ make build # build the package
152
+ ```
153
+
154
+ Single test: `poetry run pytest -v -s tests/test_peer.py::test_ban`
155
+
156
+ Layout:
157
+
158
+ | Path | Purpose |
159
+ | --- | --- |
160
+ | `src/pyrak/peer.py` | `RakPeer`: async client/server, sockets, offline handshake |
161
+ | `src/pyrak/session.py` | `Session`: connection state on top of `ReliabilityLayer` |
162
+ | `src/pyrak/reliability_layer.py` | reliability, ordering, split, ACK; no sockets, no clock |
163
+ | `src/pyrak/types/` | declarative wire types on rombob |
164
+ | `docs/raknet_protocol.md` | protocol documentation |
165
+
pyrak-0.1.0/README.md ADDED
@@ -0,0 +1,145 @@
1
+ # pyrak
2
+
3
+ An async implementation of the [RakNet](https://github.com/facebookarchive/RakNet) protocol in pure Python.
4
+ Built on [anyio](https://anyio.readthedocs.io/) (works with both asyncio and trio). A single `RakPeer` can act
5
+ as a client, a server, or both at once.
6
+
7
+ > Status: MVP. Verified against a real MCPE client (see [TODO.md](TODO.md)).
8
+
9
+ ## Features
10
+
11
+ - Offline handshake and connection: `OpenConnectionRequest1/2`, `ConnectionRequest`, `NewIncomingConnection`,
12
+ MTU negotiation, protocol version check, IP bans
13
+ - All reliability modes: `UNRELIABLE`, `UNRELIABLE_SEQUENCED`, `RELIABLE`, `RELIABLE_ORDERED`, `RELIABLE_SEQUENCED`
14
+ - Ordering channels, send priorities, splitting of large messages, ACK/NAK and retransmission
15
+ - Connected/unconnected ping (RTT, and MOTD via `UnconnectedPong`), timeouts and graceful disconnect
16
+ - Declarative wire types on [rombob](https://pypi.org/project/rombob/); your own messages are carried as `UserMessage`
17
+ - `ReliabilityLayer` has no sockets and no clock (time is passed in), so it is easy to test
18
+
19
+ Not implemented yet: congestion control, security/cookie handshake, ack receipts, NAT punchthrough.
20
+
21
+ ## Installation
22
+
23
+ Requires Python 3.11+.
24
+
25
+ ```bash
26
+ pip install pyrak
27
+ ```
28
+
29
+ Or install the latest unreleased code straight from Git:
30
+
31
+ ```bash
32
+ pip install git+https://github.com/loudblow/rombob.git@main
33
+ ```
34
+
35
+
36
+ The `rombob` dependency is pulled from a GitHub release.
37
+
38
+ ## Server
39
+
40
+ ```python
41
+ import anyio
42
+
43
+ from pyrak import (
44
+ RELIABLE_ORDERED,
45
+ ConnectionLost,
46
+ DisconnectionNotification,
47
+ NewIncomingConnection,
48
+ RakPeer,
49
+ UserMessage,
50
+ )
51
+
52
+
53
+ async def main() -> None:
54
+ async with RakPeer(max_connections=10, max_incoming_connections=10) as server:
55
+ server.payload = "MCPE;pyrak;122;;0;10;0;hello;Creative;1;19132;19133;" # MOTD
56
+ await server.listen(("0.0.0.0", 19132))
57
+
58
+ async for packet in server: # packet.address, packet.guid, packet.message
59
+ match packet.message:
60
+ case NewIncomingConnection():
61
+ print(f"{packet.address} connected")
62
+ case UserMessage(id=0x86, payload=data):
63
+ # echo back to the same client
64
+ await server.send(
65
+ packet.guid, UserMessage(0x87, data), RELIABLE_ORDERED
66
+ )
67
+ case DisconnectionNotification() | ConnectionLost():
68
+ print(f"{packet.address} left")
69
+
70
+
71
+ anyio.run(main)
72
+ ```
73
+
74
+ [`examples/mcpe_server.py`](examples/mcpe_server.py) is a server that shows up in the server list of a real
75
+ Minecraft PE client and receives its first game packet (`0xFE`):
76
+
77
+ ```bash
78
+ poetry run python examples/mcpe_server.py 19132
79
+ ```
80
+
81
+ ## Client
82
+
83
+ ```python
84
+ import anyio
85
+
86
+ from pyrak import RELIABLE_ORDERED, RakPeer, UserMessage
87
+
88
+
89
+ async def main() -> None:
90
+ async with RakPeer(max_connections=1) as client:
91
+ server = ("127.0.0.1", 19132)
92
+
93
+ # unconnected ping: fetch the server's MOTD
94
+ pong = await client.ping(server)
95
+ print("MOTD:", pong.payload if pong else "no answer")
96
+
97
+ session = await client.connect(server) # waits for the handshake
98
+ print("RTT, ms:", await client.ping(server, connected=True))
99
+
100
+ await client.send(server, UserMessage(0x86, b"hello"), RELIABLE_ORDERED)
101
+ # or raw bytes: the first byte is the message id
102
+ await client.send(server, b"\x86hello", RELIABLE_ORDERED, channel=1)
103
+
104
+ packet = await client.receive()
105
+ print(packet.message)
106
+
107
+ await client.disconnect(session)
108
+
109
+
110
+ anyio.run(main)
111
+ ```
112
+
113
+ Connection failures (`ConnectionBannedError`, `IncompatibleProtocolVersionError`,
114
+ `NoFreeIncomingConnectionsError`, `AlreadyConnectedError`, ...) are defined in `pyrak.errors`.
115
+
116
+ ## Management
117
+
118
+ ```python
119
+ server.ban("1.2.3.4", duration=60_000) # ban for 60 seconds (0 = permanent)
120
+ server.unban("1.2.3.4")
121
+ server.sessions # active sessions
122
+ await server.disconnect(packet.guid) # close a session gracefully
123
+ await server.shutdown(block_duration=500)
124
+ ```
125
+
126
+ ## Development
127
+
128
+ ```bash
129
+ make install # set up the environment
130
+ make test # tests with coverage
131
+ make lint # ruff via pre-commit
132
+ make build # build the package
133
+ ```
134
+
135
+ Single test: `poetry run pytest -v -s tests/test_peer.py::test_ban`
136
+
137
+ Layout:
138
+
139
+ | Path | Purpose |
140
+ | --- | --- |
141
+ | `src/pyrak/peer.py` | `RakPeer`: async client/server, sockets, offline handshake |
142
+ | `src/pyrak/session.py` | `Session`: connection state on top of `ReliabilityLayer` |
143
+ | `src/pyrak/reliability_layer.py` | reliability, ordering, split, ACK; no sockets, no clock |
144
+ | `src/pyrak/types/` | declarative wire types on rombob |
145
+ | `docs/raknet_protocol.md` | protocol documentation |
@@ -0,0 +1,57 @@
1
+ [project]
2
+ name = "pyrak"
3
+ version = "0.1.0"
4
+ description = "An async implementation of the RakNet protocol"
5
+ authors = [
6
+ {name = "loudblow", email = "145815114+loudblow@users.noreply.github.com"}
7
+ ]
8
+ readme = "README.md"
9
+ license = "Apache-2.0"
10
+ license-files = ["LICENSE"]
11
+ requires-python = ">=3.11"
12
+ dependencies = [
13
+ "anyio (>=4.12.1,<5.0.0)",
14
+ "rombob (>=1.1.0,<2.0.0)",
15
+ ]
16
+
17
+ [project.urls]
18
+ Source = "https://github.com/loudblow/pyrak/"
19
+
20
+ [tool.pytest.ini_options]
21
+ pythonpath = ["src"]
22
+ testpaths = ["tests"]
23
+
24
+ [tool.ruff]
25
+ src = ["src"]
26
+ fix = true
27
+ show-fixes = true
28
+ output-format = "full"
29
+ line-length = 80
30
+
31
+ [tool.ruff.lint]
32
+ select = [
33
+ "B", # flake8-bugbear
34
+ "E", # pycodestyle error
35
+ "F", # pyflakes
36
+ "I", # isort
37
+ "UP", # pyupgrade
38
+ "W", # pycodestyle warning
39
+ ]
40
+
41
+ [tool.ruff.lint.isort]
42
+ force-single-line = false
43
+ order-by-type = true
44
+
45
+ [tool.poetry]
46
+ packages = [{include = "*", from="src"}]
47
+ package-mode = true
48
+
49
+ [tool.poetry.group.dev.dependencies]
50
+ pytest = "^9.0.2"
51
+ pytest-coverage = "~0.0"
52
+ ruff = "~0.15.7"
53
+ pre-commit = "^4.5.1"
54
+
55
+ [build-system]
56
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
57
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,38 @@
1
+ """pyrak: a Python implementation of the RakNet protocol."""
2
+
3
+ from .enums import RELIABLE as RELIABLE
4
+ from .enums import RELIABLE_ORDERED as RELIABLE_ORDERED
5
+ from .enums import RELIABLE_SEQUENCED as RELIABLE_SEQUENCED
6
+ from .enums import UNRELIABLE as UNRELIABLE
7
+ from .enums import UNRELIABLE_SEQUENCED as UNRELIABLE_SEQUENCED
8
+ from .enums import ConnectMode as ConnectMode
9
+ from .enums import MessageID as MessageID
10
+ from .enums import Priority as Priority
11
+ from .enums import Reliability as Reliability
12
+ from .errors import AlreadyConnectedError as AlreadyConnectedError
13
+ from .errors import ConnectionAttemptFailedError as ConnectionAttemptFailedError
14
+ from .errors import ConnectionBannedError as ConnectionBannedError
15
+ from .errors import (
16
+ IncompatibleProtocolVersionError as IncompatibleProtocolVersionError,
17
+ )
18
+ from .errors import (
19
+ NoFreeIncomingConnectionsError as NoFreeIncomingConnectionsError,
20
+ )
21
+ from .errors import PeerClosedError as PeerClosedError
22
+ from .errors import PeerNotStartedError as PeerNotStartedError
23
+ from .errors import RakError as RakError
24
+ from .errors import SessionClosedError as SessionClosedError
25
+ from .errors import SessionNotFound as SessionNotFound
26
+ from .peer import RakPeer as RakPeer
27
+ from .reliability_layer import ReliabilityLayer as ReliabilityLayer
28
+ from .session import Session as Session
29
+ from .types import (
30
+ ConnectionAttemptFailed as ConnectionAttemptFailed,
31
+ )
32
+ from .types import ConnectionLost as ConnectionLost
33
+ from .types import ConnectionRequestAccepted as ConnectionRequestAccepted
34
+ from .types import DisconnectionNotification as DisconnectionNotification
35
+ from .types import NewIncomingConnection as NewIncomingConnection
36
+ from .types import Packet as Packet
37
+ from .types import UnconnectedPong as UnconnectedPong
38
+ from .types import UserMessage as UserMessage
@@ -0,0 +1,70 @@
1
+ import binascii
2
+ import os
3
+ import typing as t
4
+
5
+ IP_HEADER_SIZE: t.Final[int] = 20
6
+ UDP_HEADER_SIZE: t.Final[int] = 8
7
+ PACKET_HEADER_SIZE: t.Final[int] = IP_HEADER_SIZE + UDP_HEADER_SIZE
8
+ FRAME_SET_HEADER_SIZE: t.Final[int] = 4
9
+ "packet type (1 byte) + sequence_num (3 bytes)"
10
+ RAKNET_HEADER_SIZE: t.Final[int] = 8
11
+ ALL_HEADER_SIZE: t.Final[int] = (
12
+ PACKET_HEADER_SIZE + RAKNET_HEADER_SIZE + FRAME_SET_HEADER_SIZE
13
+ )
14
+
15
+
16
+ # 1500. The largest Ethernet packet size recommended. This is the
17
+ # typical setting for non-PPPoE, non-VPN connections. The default
18
+ # value for NETGEAR routers, adapters and switches.
19
+ # 1492. The size PPPoE prefers.
20
+ # 1472. Maximum size to use for pinging. (Bigger packets are fragmented.)
21
+ # 1468. The size DHCP prefers.
22
+ # 1460. Usable by AOL if you don't have large email attachments, etc.
23
+ # 1430. The size VPN and PPTP prefer.
24
+ # 1400. Maximum size for AOL DSL.
25
+ # 576. Typical value to connect to dial-up ISPs.
26
+ #
27
+ # Source: https://github.com/facebookarchive/RakNet/blob/1a169895a900c9fc4841c556e16514182b75faf8/Source/MTUSize.h
28
+ MAX_MTU_SIZE: t.Final[int] = 1492
29
+ MIN_MTU_SIZE: t.Final[int] = 400
30
+ SESSION_TIMEOUT: t.Final[int] = 10000 if not __debug__ else 30000
31
+ RAKNET_PROTOCOL_VERSION: t.Final[int] = 6
32
+ """Default vanilla RakNet protocol version that this library
33
+ implements.
34
+
35
+ Source: https://github.com/facebookarchive/RakNet/blob/1a169895a900c9fc4841c556e16514182b75faf8/Source/RakNetVersion.h#L19
36
+ """
37
+ MAX_LOCAL_ADDRESSES: t.Final[int] = int(
38
+ os.environ.get("PYRAK_MAX_LOCAL_ADDRESSES", "20")
39
+ )
40
+ """Maximum number of local IP addresses supported.
41
+ Regular RakNet uses 10 by default, MCPE and its successors use 20.
42
+
43
+ Source: https://github.com/facebookarchive/RakNet/blob/1a169895a900c9fc4841c556e16514182b75faf8/Source/RakNetDefines.h#L76
44
+ """
45
+ MAX_OFFLINE_DATA_LENGTH: t.Final[int] = 400
46
+
47
+ MAGIC: t.Final[bytes] = binascii.unhexlify(b"00ffff00fefefefefdfdfdfd12345678")
48
+ """
49
+ Unconnected message signature, those bytes used to identify the type of a
50
+ UDP-message (unconnected or reliabile).
51
+ Source: https://github.com/facebookarchive/RakNet/blob/1a169895a900c9fc4841c556e16514182b75faf8/Source/RakPeer.cpp#L135
52
+ """
53
+
54
+ RESEND_TIME: t.Final[int] = 500
55
+ "ms, a fixed retransmission timeout of a reliable frame"
56
+ PING_INTERVAL: t.Final[int] = 5000
57
+ "ms, how often a connected ping is sent"
58
+ UPDATE_INTERVAL: t.Final[int] = 10
59
+ "ms, how often RakPeer updates its sessions"
60
+ MAX_SPLIT_COUNT: t.Final[int] = 16384
61
+ "The maximum number of parts a split message may have."
62
+ MAX_SPLIT_ENTRIES: t.Final[int] = 256
63
+ "The maximum number of incomplete split messages per session."
64
+ MAX_ORDERING_QUEUE: t.Final[int] = 2048
65
+ "The maximum number of out-of-order frames cached per channel."
66
+ ORDERING_CHANNELS: t.Final[int] = 32
67
+ MAX_DATAGRAMS_PER_UPDATE: t.Final[int] = 128
68
+ "Pacing: the maximum number of frame sets sent per session per update."
69
+ MTU_SIZES: t.Final[tuple[int, ...]] = (MAX_MTU_SIZE, 1200, 576)
70
+ "MTU sizes a client probes during the offline handshake."