diff --git a/PhyConDebugLogging.xml b/PhyConDebugLogging.xml new file mode 100644 index 0000000..62f2153 --- /dev/null +++ b/PhyConDebugLogging.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/build.gradle b/build.gradle index 58d0ef1..bca3339 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "fabric-loom" version "0.5-SNAPSHOT" + id "fabric-loom" version "0.6.49" id "maven-publish" id "org.jetbrains.kotlin.jvm" version "1.4.30" } @@ -12,6 +12,7 @@ version = project.mod_version group = project.maven_group minecraft { + log4jConfigs.from "PhyConDebugLogging.xml" } repositories { diff --git a/src/main/kotlin/net/shadowfacts/phycon/PhysicalConnectivity.kt b/src/main/kotlin/net/shadowfacts/phycon/PhysicalConnectivity.kt index 961dbee..d43573f 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/PhysicalConnectivity.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/PhysicalConnectivity.kt @@ -7,6 +7,7 @@ import net.shadowfacts.phycon.init.PhyBlocks import net.shadowfacts.phycon.init.PhyItems import net.shadowfacts.phycon.init.PhyScreens import net.shadowfacts.phycon.networking.* +import org.apache.logging.log4j.LogManager /** * @author shadowfacts @@ -15,6 +16,8 @@ object PhysicalConnectivity: ModInitializer { val MODID = "phycon" + val NETWORK_LOGGER = LogManager.getLogger("PhyNet") + override fun onInitialize() { PhyBlocks.init() PhyBlockEntities.init() diff --git a/src/main/kotlin/net/shadowfacts/phycon/network/DeviceBlockEntity.kt b/src/main/kotlin/net/shadowfacts/phycon/network/DeviceBlockEntity.kt index 4ce619a..b30553b 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/network/DeviceBlockEntity.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/network/DeviceBlockEntity.kt @@ -6,6 +6,7 @@ import net.minecraft.block.entity.BlockEntity import net.minecraft.block.entity.BlockEntityType import net.minecraft.nbt.CompoundTag import net.minecraft.util.Tickable +import net.shadowfacts.phycon.PhysicalConnectivity import net.shadowfacts.phycon.api.PacketSink import net.shadowfacts.phycon.api.PacketSource import net.shadowfacts.phycon.api.Interface @@ -52,6 +53,7 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type), abstract override fun handle(packet: Packet) private fun doHandlePacket(packet: Packet) { + PhysicalConnectivity.NETWORK_LOGGER.debug("{} ({}) received packet: {}", this, ipAddress, packet) when (packet) { is DeviceRemovedPacket -> { arpTable.remove(packet.source) @@ -65,13 +67,12 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type), } override fun receive(frame: EthernetFrame) { - println("$this ($ipAddress, ${macAddress}) received frame from ${frame.source}: $frame") + PhysicalConnectivity.NETWORK_LOGGER.debug("{} ({}, {}) received frame from {}: {}", this, ipAddress, macAddress, frame.source, frame) when (frame) { is ARPQueryFrame -> handleARPQuery(frame) is ARPResponseFrame -> handleARPResponse(frame) is PacketFrame -> { if (frame.packet.destination.isBroadcast || frame.packet.destination == ipAddress) { - println("$this ($ipAddress) received packet: ${frame.packet}") doHandlePacket(frame.packet) } } @@ -79,17 +80,17 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type), } private fun handleARPQuery(frame: ARPQueryFrame) { - println("$this ($ipAddress) received ARP query for ${frame.queryIP}") + PhysicalConnectivity.NETWORK_LOGGER.debug("{}, ({}), received ARP query for {}", this, ipAddress, frame.queryIP) arpTable[frame.sourceIP] = frame.source if (frame.queryIP == ipAddress) { - println("$this ($ipAddress) sending ARP response to ${frame.source} with $macAddress") + PhysicalConnectivity.NETWORK_LOGGER.debug("{} ({}) sending ARP response to {} with {}", this, ipAddress, frame.sourceIP, macAddress) send(ARPResponseFrame(ipAddress, macAddress, frame.source)) } } private fun handleARPResponse(frame: ARPResponseFrame) { arpTable[frame.query] = frame.source - println("$this ($ipAddress) received ARP response for ${frame.query} with ${frame.source}") + PhysicalConnectivity.NETWORK_LOGGER.debug("{}, ({}) received ARP response for {} with {}", this, ipAddress, frame.query, frame.source) val toRemove = packetQueue.filter { (packet, _) -> if (packet.destination == frame.query) { @@ -110,7 +111,7 @@ abstract class DeviceBlockEntity(type: BlockEntityType<*>): BlockEntity(type), } else { packetQueue.add(PendingPacket(packet, counter)) - println("$this ($ipAddress) sending ARP query for ${packet.destination}") + PhysicalConnectivity.NETWORK_LOGGER.debug("{} ({}) sending ARP query for {}", this, ipAddress, packet.destination) send(ARPQueryFrame(packet.destination, ipAddress, macAddress)) } } diff --git a/src/main/kotlin/net/shadowfacts/phycon/network/block/netswitch/SwitchBlockEntity.kt b/src/main/kotlin/net/shadowfacts/phycon/network/block/netswitch/SwitchBlockEntity.kt index 51d0d51..23c54b8 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/network/block/netswitch/SwitchBlockEntity.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/network/block/netswitch/SwitchBlockEntity.kt @@ -7,6 +7,7 @@ import net.minecraft.entity.ItemEntity import net.minecraft.nbt.CompoundTag import net.minecraft.util.Tickable import net.minecraft.util.math.Direction +import net.shadowfacts.phycon.PhysicalConnectivity import net.shadowfacts.phycon.api.Interface import net.shadowfacts.phycon.api.frame.EthernetFrame import net.shadowfacts.phycon.api.frame.PacketFrame @@ -53,10 +54,10 @@ class SwitchBlockEntity: BlockEntity(PhyBlockEntities.SWITCH), if (frame.destination.type != MACAddress.Type.BROADCAST && macTable.containsKey(frame.destination)) { val dir = macTable[frame.destination]!! - println("$this (${fromItf.side}, ${fromItf.macAddress}) forwarding $frame to side $dir") + PhysicalConnectivity.NETWORK_LOGGER.debug("{} ({}, {}) forwarding {} to side {}", this, fromItf.side, fromItf.macAddress, frame, dir) interfaceForSide(dir).send(frame) } else { - println("$this (${fromItf.side}, ${fromItf.macAddress}) flooding $frame") + PhysicalConnectivity.NETWORK_LOGGER.debug("{} ({}, {}) flooding {}", this, fromItf.side, fromItf.macAddress, frame) flood(frame, fromItf) } }