From d82b1b688d5f13d420a52ebb74ee4ef385bd5f97 Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Sat, 30 May 2020 11:57:33 -0700 Subject: [PATCH] Change DNS error printing to a debug printing flag. --- .../com/github/steveice10/packetlib/BuiltinFlags.java | 5 ++--- .../steveice10/packetlib/tcp/TcpClientSession.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/steveice10/packetlib/BuiltinFlags.java b/src/main/java/com/github/steveice10/packetlib/BuiltinFlags.java index f81c505b..9937bd31 100644 --- a/src/main/java/com/github/steveice10/packetlib/BuiltinFlags.java +++ b/src/main/java/com/github/steveice10/packetlib/BuiltinFlags.java @@ -5,10 +5,9 @@ package com.github.steveice10.packetlib; */ public class BuiltinFlags { /** - * When set to true, prints exceptions that occur when attempting - * to resolve DNS SRV records, rather than silently ignoring them. + * When set to true, enables printing internal debug messages. */ - public static final String PRINT_DNS_ERRORS = "print-dns-errors"; + public static final String PRINT_DEBUG = "print-packetlib-debug"; private BuiltinFlags() { } diff --git a/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java b/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java index a87288be..b796468f 100644 --- a/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java +++ b/src/main/java/com/github/steveice10/packetlib/tcp/TcpClientSession.java @@ -102,6 +102,8 @@ public class TcpClientSession extends TcpSession { @Override public void run() { try { + boolean debug = getFlag(BuiltinFlags.PRINT_DEBUG, false); + String host = getHost(); int port = getPort(); @@ -112,9 +114,16 @@ public class TcpClientSession extends TcpSession { host = srv.getTarget().toString().replaceFirst("\\.$", ""); port = srv.getPort(); + + if(debug) { + System.out.println("[PacketLib] Found SRV record for \"" + host + ":" + port + "\"."); + } + } else if(debug) { + System.out.println("[PacketLib] No SRV records found."); } } catch(TextParseException e) { - if(getFlag(BuiltinFlags.PRINT_DNS_ERRORS, false)) { + if(debug) { + System.out.println("[PacketLib] Failed to resolve SRV record."); e.printStackTrace(); } }