Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IS_IPB packet and TINY_IPB subtype of IS_TINY #47

Closed
mkapal opened this issue Jul 28, 2024 · 2 comments
Closed

Add IS_IPB packet and TINY_IPB subtype of IS_TINY #47

mkapal opened this issue Jul 28, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request released

Comments

@mkapal
Copy link
Member

mkapal commented Jul 28, 2024

A new IS_IPB packet was introduced in LFS version 0.7F.

Source code from InSim.txt:

// IP Bans

// You can set up to 120 IP addresses that are not allowed to join a host

const int IPB_MAX_BANS = 120;

struct IS_IPB // IP Bans - variable size
{
	byte	Size;		// 8 + NumB * 4
	byte	Type;		// ISP_IPB
	byte	ReqI;		// 0 unless this is a reply to a TINY_IPB request
	byte	NumB;		// number of bans in this packet

	byte	Sp0;
	byte	Sp1;
	byte	Sp2;
	byte	Sp3;

	in_addr		BanIPs	[MAL_MAX_MODS]; // IP addresses, 0 to IPB_MAX_BANS (NumB)
};

Also the IS_TINY enum has been updated with a new subtype added at the end:

TINY_IPB,		// 29 - info request	: send IS_IPB listing the IP bans

IP address handling

As of now, the only use case of handling IP addresses is in the IS_NCI packet:

/** IP address formatted as 255.255.255.255 */
@unsigned() IPAddress = '';

When the packet is received, the IP address is converted into a string:

this.IPAddress = buffer.slice(12, 16).join('.');

Should it be handled the same in the new IS_IPB packet, or should all IP address fields be stored as a utility object, allowing the users to convert the IP address from/to bytes, perform validations and other useful operations?

Here are my proposed options:

Plain string

When a packet is received, the binary 4-byte integer is converted into string containing 4 numbers separated by dots.

When a packet is sent, the IP string is parsed and converted into the 4-byte integer.

  • easy to use
  • app developers must use additional tools to convert the provided IP string into different formats
// Sending a packet
inSim.send(new IS_IPB({
  NumB: 2,
  BanIPs: ['1.2.3.4', '5.6.7.8'],
}));

// Receiving a packet
inSim.on(PacketType.ISP_IPB, (packet) => {
  console.log(packet.BanIPs[0]); // '1.2.3.4'
});

Utility object

Make use of a library capable of converting an IP address between integer, hexadecimal, string etc. and able to parse and validate an input IP.

  • need to wrap each IP into a class constructor
// Sending a packet
inSim.send(new IS_IPB({
  NumB: 2,
  BanIPs: [new Address4('1.2.3.4'), new Address4('5.6.7.8')],
}));

// Sending an invalid IP
inSim.send(new IS_IPB({
  NumB: 2,
  BanIPs: [new Address4('455.34.56788.23')],
})); // -> Throws a runtime validation error

// Receiving a packet
inSim.on(PacketType.ISP_IPB, (packet) => {
  // string representation
  console.log(packet.BanIPs[0].address); // '1.2.3.4'

  // byte array
  console.log(packet.BanIPs[0].toArray()); // [1,2,3,4]
});

Examples of such libraries:

https://github.com/indutny/node-ip
https://github.com/beaugunderson/ip-address

@mkapal mkapal self-assigned this Jul 28, 2024
@mkapal mkapal added the enhancement New feature or request label Jul 28, 2024
mkapal added a commit that referenced this issue Jul 28, 2024
You can use the IS_IPB packet to set up to 120 IPv4 addresses that are not allowed to join a host.

fix #47
mkapal added a commit that referenced this issue Jul 28, 2024
Added `TINY_IPB` into the `TinyType` enum.

fix #47
mkapal added a commit that referenced this issue Jul 28, 2024
You can use the IS_IPB packet to set up to 120 IPv4 addresses that are not allowed to join a host.

The IP addresses assigned to the `BanIPs` property must be in a string format `X.X.X.X` where `X` is a number from 0 to 255. If some of the IP addresses are invalid, a `RangeError` will be thrown.

fix #47
mkapal added a commit that referenced this issue Jul 28, 2024
Added `TINY_IPB` into the `TinyType` enum.

fix #47
@mkapal
Copy link
Member Author

mkapal commented Jul 28, 2024

I have decided to do start simple and only work with strings on the consumer side. Also, I have added validation when sending a range of IPs. If some of the IPs don't conform to the IPv4 format, a RangeError will be thrown. See #48

mkapal added a commit that referenced this issue Jul 28, 2024
You can use the IS_IPB packet to set up to 120 IPv4 addresses that are not allowed to join a host.

The IP addresses assigned to the `BanIPs` property must be in a string format `X.X.X.X` where `X` is a number from 0 to 255. If some of the IP addresses are invalid, a `RangeError` will be thrown.

fix #47
mkapal added a commit that referenced this issue Jul 28, 2024
Added `TINY_IPB` into the `TinyType` enum.

fix #47
mkapal added a commit that referenced this issue Jul 28, 2024
You can use the IS_IPB packet to set up to 120 IPv4 addresses that are not allowed to join a host.

The IP addresses assigned to the `BanIPs` property must be in a string format `X.X.X.X` where `X` is a number from 0 to 255. If some of the IP addresses are invalid, a `RangeError` will be thrown.

fix #47
mkapal added a commit that referenced this issue Jul 28, 2024
Added `TINY_IPB` into the `TinyType` enum.

fix #47
@mkapal mkapal closed this as completed in 0b86949 Jul 28, 2024
mkapal added a commit that referenced this issue Jul 28, 2024
Added `TINY_IPB` into the `TinyType` enum.

fix #47
Copy link

🎉 This issue has been resolved in version 4.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

No branches or pull requests

1 participant