From 7f5a5d40dc2dc3dc608639830a4a6a16763f45eb Mon Sep 17 00:00:00 2001
From: Torsten Grote <t@grobox.de>
Date: Tue, 6 Dec 2016 15:36:54 -0200
Subject: [PATCH] Remove verbose logging from introduction client

---
 .../briar/introduction/IntroduceeEngine.java  | 54 ++++----------
 .../briar/introduction/IntroducerEngine.java  | 71 +++++--------------
 .../briar/introduction/IntroducerManager.java |  1 -
 .../introduction/IntroductionManagerImpl.java | 16 ++---
 4 files changed, 40 insertions(+), 102 deletions(-)

diff --git a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeEngine.java b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeEngine.java
index e7c213d999..f93fb0aa41 100644
--- a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeEngine.java
+++ b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroduceeEngine.java
@@ -266,14 +266,6 @@ class IntroduceeEngine
 		m.put(SESSION_ID, localState.getRaw(SESSION_ID));
 		m.put(MAC, localState.getRaw(OUR_MAC));
 		m.put(SIGNATURE, localState.getRaw(OUR_SIGNATURE));
-
-		if (LOG.isLoggable(INFO)) {
-			LOG.info("Sending ACK " + " to " +
-					localState.getString(INTRODUCER) + " for " +
-					localState.getString(NAME) + " with session ID " +
-					Arrays.hashCode(m.getRaw(SESSION_ID)) + " in group " +
-					Arrays.hashCode(m.getRaw(GROUP_ID)));
-		}
 		return m;
 	}
 
@@ -285,14 +277,9 @@ class IntroduceeEngine
 		try {
 			LOG.info("Sending " +
 					(localState.getBoolean(ACCEPT) ? "accept " : "decline ") +
-					"response in state " + state.name() +
-					" to " + localState.getString(INTRODUCER) +
-					" for " + localState.getString(NAME) + " with session ID " +
-					Arrays.hashCode(msg.getRaw(SESSION_ID)) + " in group " +
-					Arrays.hashCode(msg.getRaw(GROUP_ID)) + ". " +
-					"Moving on to state " +
-					getState(localState.getLong(STATE)).name()
-			);
+					"response in state " + state.name());
+			LOG.info("Moving on to state " +
+					getState(localState.getLong(STATE)).name());
 		} catch (FormatException e) {
 			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
@@ -304,25 +291,14 @@ class IntroduceeEngine
 
 		if (!LOG.isLoggable(INFO)) return;
 
-		try {
-			String t = "unknown";
-			if (type == TYPE_REQUEST) t = "Introduction";
-			else if (type == TYPE_RESPONSE) t = "Response";
-			else if (type == TYPE_ACK) t = "ACK";
-			else if (type == TYPE_ABORT) t = "Abort";
-
-			LOG.info("Received " + t + " in state " + currentState.name() +
-					" from " + localState.getString(INTRODUCER) +
-					(localState.containsKey(NAME) ?
-							" related to " + localState.getString(NAME) : "") +
-					" with session ID " +
-					Arrays.hashCode(msg.getRaw(SESSION_ID)) + " in group " +
-					Arrays.hashCode(msg.getRaw(GROUP_ID)) + ". " +
-					"Moving on to state " + nextState.name()
-			);
-		} catch (FormatException e) {
-			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		}
+		String t = "unknown";
+		if (type == TYPE_REQUEST) t = "Introduction";
+		else if (type == TYPE_RESPONSE) t = "Response";
+		else if (type == TYPE_ACK) t = "ACK";
+		else if (type == TYPE_ABORT) t = "Abort";
+
+		LOG.info("Received " + t + " in state " + currentState.name());
+		LOG.info("Moving on to state " + nextState.name());
 	}
 
 	@Override
@@ -368,11 +344,9 @@ class IntroduceeEngine
 			IntroduceeProtocolState currentState, BdfDictionary localState)
 			throws FormatException {
 
-		if (LOG.isLoggable(WARNING)) {
-			LOG.warning("Aborting protocol session " +
-					Arrays.hashCode(localState.getRaw(SESSION_ID)) +
-					" in state " + currentState.name());
-		}
+		if (LOG.isLoggable(WARNING))
+			LOG.warning("Aborting protocol session in state " +
+					currentState.name());
 
 		localState.put(STATE, ERROR.getValue());
 		localState.put(TASK, TASK_ABORT);
diff --git a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerEngine.java b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerEngine.java
index ea08aebd77..b0cffd95ba 100644
--- a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerEngine.java
+++ b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerEngine.java
@@ -114,7 +114,7 @@ class IntroducerEngine
 				}
 				msg1.put(MESSAGE_TIME, localAction.getLong(MESSAGE_TIME));
 				messages.add(msg1);
-				logLocalAction(currentState, localState, msg1);
+				logLocalAction(currentState, localState);
 				BdfDictionary msg2 = new BdfDictionary();
 				msg2.put(TYPE, TYPE_REQUEST);
 				msg2.put(SESSION_ID, localState.getRaw(SESSION_ID));
@@ -126,7 +126,7 @@ class IntroducerEngine
 				}
 				msg2.put(MESSAGE_TIME, localAction.getLong(MESSAGE_TIME));
 				messages.add(msg2);
-				logLocalAction(currentState, localState, msg2);
+				logLocalAction(currentState, localState);
 
 				List<Event> events = Collections.emptyList();
 				return new StateUpdate<BdfDictionary, BdfDictionary>(false,
@@ -214,19 +214,13 @@ class IntroducerEngine
 	}
 
 	private void logLocalAction(IntroducerProtocolState state,
-			BdfDictionary localState, BdfDictionary msg) {
+			BdfDictionary localState) {
 
 		if (!LOG.isLoggable(INFO)) return;
-
 		try {
-			String to = getMessagePartner(localState, msg);
-			LOG.info("Sending introduction request in state " + state.name() +
-					" to " + to + " with session ID " +
-					Arrays.hashCode(msg.getRaw(SESSION_ID)) + " in group " +
-					Arrays.hashCode(msg.getRaw(GROUP_ID)) + ". " +
-					"Moving on to state " +
-					getState(localState.getLong(STATE)).name()
-			);
+			LOG.info("Sending introduction request in state " + state.name());
+			LOG.info("Moving on to state " +
+					getState(localState.getLong(STATE)).name());
 		} catch (FormatException e) {
 			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
 		}
@@ -235,28 +229,17 @@ class IntroducerEngine
 	private void logMessageReceived(IntroducerProtocolState currentState,
 			IntroducerProtocolState nextState,
 			BdfDictionary localState, int type, BdfDictionary msg) {
+
 		if (!LOG.isLoggable(INFO)) return;
 
-		try {
-			String t = "unknown";
-			if (type == TYPE_REQUEST) t = "Introduction";
-			else if (type == TYPE_RESPONSE) t = "Response";
-			else if (type == TYPE_ACK) t = "ACK";
-			else if (type == TYPE_ABORT) t = "Abort";
-
-			String from = getMessagePartner(localState, msg);
-			String to = getOtherContact(localState, msg);
-
-			LOG.info("Received " + t + " in state " + currentState.name() +
-					" from " +
-					from + " to " + to + " with session ID " +
-					Arrays.hashCode(msg.getRaw(SESSION_ID)) + " in group " +
-					Arrays.hashCode(msg.getRaw(GROUP_ID)) + ". " +
-					"Moving on to state " + nextState.name()
-			);
-		} catch (FormatException e) {
-			if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
-		}
+		String t = "unknown";
+		if (type == TYPE_REQUEST) t = "Introduction";
+		else if (type == TYPE_RESPONSE) t = "Response";
+		else if (type == TYPE_ACK) t = "ACK";
+		else if (type == TYPE_ABORT) t = "Abort";
+
+		LOG.info("Received " + t + " in state " + currentState.name());
+		LOG.info("Moving on to state " + nextState.name());
 	}
 
 	private List<BdfDictionary> forwardMessage(BdfDictionary localState,
@@ -270,11 +253,6 @@ class IntroducerEngine
 			msg.put(GROUP_ID, localState.getRaw(GROUP_ID_1));
 		}
 
-		if (LOG.isLoggable(INFO)) {
-			LOG.info("Forwarding message to group " +
-					Arrays.hashCode(msg.getRaw(GROUP_ID)));
-		}
-
 		return Collections.singletonList(msg);
 	}
 
@@ -336,17 +314,6 @@ class IntroducerEngine
 		}
 	}
 
-	private String getMessagePartner(BdfDictionary localState,
-			BdfDictionary msg) throws FormatException {
-
-		String from = localState.getString(CONTACT_1);
-		if (Arrays
-				.equals(msg.getRaw(GROUP_ID), localState.getRaw(GROUP_ID_2))) {
-			from = localState.getString(CONTACT_2);
-		}
-		return from;
-	}
-
 	private String getOtherContact(BdfDictionary localState, BdfDictionary msg)
 			throws FormatException {
 
@@ -362,11 +329,9 @@ class IntroducerEngine
 			IntroducerProtocolState currentState, BdfDictionary localState)
 			throws FormatException {
 
-		if (LOG.isLoggable(WARNING)) {
-			LOG.warning("Aborting protocol session " +
-					Arrays.hashCode(localState.getRaw(SESSION_ID)) +
-					" in state " + currentState.name());
-		}
+		if (LOG.isLoggable(WARNING))
+			LOG.warning("Aborting protocol session in state " +
+					currentState.name());
 
 		localState.put(STATE, ERROR.getValue());
 		List<BdfDictionary> messages = new ArrayList<BdfDictionary>(2);
diff --git a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerManager.java b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerManager.java
index 07e031c632..09b6975adb 100644
--- a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerManager.java
+++ b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroducerManager.java
@@ -167,7 +167,6 @@ class IntroducerManager {
 	}
 
 	public void abort(Transaction txn, BdfDictionary state) {
-
 		IntroducerEngine engine = new IntroducerEngine();
 		BdfDictionary localAction = new BdfDictionary();
 		localAction.put(TYPE, TYPE_ABORT);
diff --git a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroductionManagerImpl.java b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroductionManagerImpl.java
index 6b3884138f..6ed619249c 100644
--- a/briar-core/src/main/java/org/briarproject/briar/introduction/IntroductionManagerImpl.java
+++ b/briar-core/src/main/java/org/briarproject/briar/introduction/IntroductionManagerImpl.java
@@ -436,7 +436,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
 						list.add(ir);
 					}
 				} catch (FormatException e) {
-					if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
+					if (LOG.isLoggable(WARNING))
+						LOG.log(WARNING, e.toString(), e);
 				}
 			}
 			db.commitTransaction(txn);
@@ -455,7 +456,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
 			return state.getString(CONTACT_2);
 		if (contactId.getInt() == state.getLong(CONTACT_ID_2).intValue())
 			return state.getString(CONTACT_1);
-		throw new RuntimeException("Contact not part of this introduction session");
+		throw new RuntimeException(
+				"Contact not part of this introduction session");
 	}
 
 	private AuthorId getAuthorIdForIntroducer(ContactId contactId,
@@ -465,7 +467,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
 			return new AuthorId(state.getRaw(AUTHOR_ID_2));
 		if (contactId.getInt() == state.getLong(CONTACT_ID_2).intValue())
 			return new AuthorId(state.getRaw(AUTHOR_ID_1));
-		throw new RuntimeException("Contact not part of this introduction session");
+		throw new RuntimeException(
+				"Contact not part of this introduction session");
 	}
 
 	private boolean concernsThisContact(ContactId contactId, MessageId messageId,
@@ -508,11 +511,8 @@ class IntroductionManagerImpl extends ConversationClientImpl
 					if (g.equals(groupId)) return state;
 				}
 			}
-			if (warn && LOG.isLoggable(WARNING)) {
-				LOG.warning(
-						"No session state found for message with session ID " +
-								Arrays.hashCode(sessionId));
-			}
+			if (warn && LOG.isLoggable(WARNING))
+				LOG.warning("No session state found");
 			throw new FormatException();
 		}
 	}
-- 
GitLab