Skip to content

Commit d19255d

Browse files
Timothé GRISOTasiekierka
authored andcommitted
Added configurable network packet TTL
1 parent 1e170bd commit d19255d

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/main/resources/application.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,13 @@ opencomputers {
12571257
# string from the clipboard (Shift+Ins on a screen with a keyboard).
12581258
maxClipboard: 1024
12591259

1260+
# The TTL (Time-To-Live) upon creation of a network packet. When a packet
1261+
# passes through a Relay, its TTL is decremented. If a Relay receives a
1262+
# packet with a TTL of 0, the packet is dropped. Minimum value is 5.
1263+
# Note: increasing this value to large numbers may have an significant
1264+
# impact on performances.
1265+
initialNetworkPacketTTL: 5
1266+
12601267
# The maximum size of network packets to allow sending via network cards.
12611268
# This has *nothing to do* with real network traffic, it's just a limit
12621269
# for the network cards, mostly to reduce the chance of computer with a

src/main/scala/li/cil/oc/Settings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ class Settings(val config: Config) {
341341
val maxScreenWidth = config.getInt("misc.maxScreenWidth") max 1
342342
val maxScreenHeight = config.getInt("misc.maxScreenHeight") max 1
343343
val inputUsername = config.getBoolean("misc.inputUsername")
344+
val initialNetworkPacketTTL = config.getInt("misc.initialNetworkPacketTTL") max 5
344345
val maxNetworkPacketSize = config.getInt("misc.maxNetworkPacketSize") max 0
345346
// Need at least 4 for nanomachine protocol. Because I can!
346347
val maxNetworkPacketParts = config.getInt("misc.maxNetworkPacketParts") max 4

src/main/scala/li/cil/oc/server/network/Network.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ object Network extends api.detail.NetworkAPI {
723723

724724
// ----------------------------------------------------------------------- //
725725

726-
class Packet(var source: String, var destination: String, var port: Int, var data: Array[AnyRef], var ttl: Int = 5) extends api.network.Packet {
726+
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 {
727727
val size = Option(data).fold(0)(values => {
728728
if (values.length > Settings.get.maxNetworkPacketParts) {
729729
throw new IllegalArgumentException("packet has too many parts")

0 commit comments

Comments
 (0)