This commit is contained in:
Fijxu 2025-01-13 11:21:21 -03:00
parent b69cd74f1a
commit 6654d7cd75
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4

View file

@ -3,7 +3,7 @@ require "benchmark"
module NatPMP module NatPMP
# Result codes defined by the RFC 6886 # Result codes defined by the RFC 6886
# #
# [RFC 6886 - 3.5. Result Codes](https://datatracker.ietf.org/doc/html/rfc6886#section-3.5) # [RFC 6886 - 3.5. Result Codes](https://datatracker.ietf.org/doc/html/rfc6886#section-3.5)
enum ResultCodes enum ResultCodes
SUCCESS = 0 SUCCESS = 0
@ -15,19 +15,19 @@ module NatPMP
end end
# Opcodes defined by the RFC 6886 # Opcodes defined by the RFC 6886
# #
# *"Otherwise, if the opcode in the request is less than 128, but is not a supported opcode **(currently 0, 1, or 2)**"* # *"Otherwise, if the opcode in the request is less than 128, but is not a supported opcode **(currently 0, 1, or 2)**"*
# #
# [RFC 6886 - 3.5. Result Codes](https://datatracker.ietf.org/doc/html/rfc6886#section-3.5) # [RFC 6886 - 3.5. Result Codes](https://datatracker.ietf.org/doc/html/rfc6886#section-3.5)
enum OP : UInt8 enum OP : UInt8
NOOP = 0_u8 NOOP = 0_u8
UDP = 1_u8 UDP = 1_u8
TCP = 2_u8 TCP = 2_u8
end end
# You can use this struct to craft your own mapping packets in case you want # You can use this struct to craft your own mapping packets in case you want
# to handle it all by yourself. # to handle it all by yourself.
# #
# ``` # ```
# # This creates a mapping that you can use to send trough a Socket # # This creates a mapping that you can use to send trough a Socket
# packet_io = NatPMP::MappingPacket.new(25565, 25565, 1, 3600).to_io # packet_io = NatPMP::MappingPacket.new(25565, 25565, 1, 3600).to_io
@ -54,11 +54,11 @@ module NatPMP
io.write_bytes(@internal_port, IO::ByteFormat::BigEndian) io.write_bytes(@internal_port, IO::ByteFormat::BigEndian)
io.write_bytes(@external_port, IO::ByteFormat::BigEndian) io.write_bytes(@external_port, IO::ByteFormat::BigEndian)
io.write_bytes(@lifetime, IO::ByteFormat::BigEndian) io.write_bytes(@lifetime, IO::ByteFormat::BigEndian)
return io io
end end
# Converts the struct instance variables to an StaticArray. # Converts the struct instance variables to an StaticArray.
# #
# Side Note: This is not actually a Slice, it's an StaticArray so I don't # Side Note: This is not actually a Slice, it's an StaticArray so I don't
# think this member function should be called like this. # think this member function should be called like this.
def to_slice def to_slice
@ -79,7 +79,7 @@ module NatPMP
slice[9] = l[1] slice[9] = l[1]
slice[10] = l[2] slice[10] = l[2]
slice[11] = l[3] slice[11] = l[3]
return slice slice
end end
end end
@ -137,7 +137,7 @@ module NatPMP
end end
end end
return msg msg
end end
# Returns the external address response as a `Slice(UInt8)` # Returns the external address response as a `Slice(UInt8)`
@ -147,7 +147,7 @@ module NatPMP
# ``` # ```
def send_external_address_request_as_bytes : Bytes def send_external_address_request_as_bytes : Bytes
msg = send_external_address_request_ msg = send_external_address_request_
return msg msg
end end
# Returns the external address response as a `Tuple(UInt8, UInt8, UInt16, UInt32, String | Nil)` # Returns the external address response as a `Tuple(UInt8, UInt8, UInt16, UInt32, String | Nil)`