Skip to content

Commit

Permalink
Added configurable network packet TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
timothe-grisot authored and asiekierka committed Jan 4, 2025
1 parent 1e170bd commit d19255d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,13 @@ opencomputers {
# string from the clipboard (Shift+Ins on a screen with a keyboard).
maxClipboard: 1024

# The TTL (Time-To-Live) upon creation of a network packet. When a packet
# passes through a Relay, its TTL is decremented. If a Relay receives a
# packet with a TTL of 0, the packet is dropped. Minimum value is 5.
# Note: increasing this value to large numbers may have an significant
# impact on performances.
initialNetworkPacketTTL: 5

# The maximum size of network packets to allow sending via network cards.
# This has *nothing to do* with real network traffic, it's just a limit
# for the network cards, mostly to reduce the chance of computer with a
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/li/cil/oc/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class Settings(val config: Config) {
val maxScreenWidth = config.getInt("misc.maxScreenWidth") max 1
val maxScreenHeight = config.getInt("misc.maxScreenHeight") max 1
val inputUsername = config.getBoolean("misc.inputUsername")
val initialNetworkPacketTTL = config.getInt("misc.initialNetworkPacketTTL") max 5
val maxNetworkPacketSize = config.getInt("misc.maxNetworkPacketSize") max 0
// Need at least 4 for nanomachine protocol. Because I can!
val maxNetworkPacketParts = config.getInt("misc.maxNetworkPacketParts") max 4
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/li/cil/oc/server/network/Network.scala
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ object Network extends api.detail.NetworkAPI {

// ----------------------------------------------------------------------- //

class Packet(var source: String, var destination: String, var port: Int, var data: Array[AnyRef], var ttl: Int = 5) extends api.network.Packet {
class Packet(var source: String, var destination: String, var port: Int, var data: Array[AnyRef], var ttl: Int = Settings.get.initialNetworkPacketTTL) extends api.network.Packet {
val size = Option(data).fold(0)(values => {
if (values.length > Settings.get.maxNetworkPacketParts) {
throw new IllegalArgumentException("packet has too many parts")
Expand Down

0 comments on commit d19255d

Please sign in to comment.