Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using Minima logger instead of s/l4j logger #476

Open
wants to merge 2 commits into
base: feature_p2p
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ repositories {
}

dependencies {
implementation 'org.slf4j:slf4j-api:1.7.32'
compile 'org.apache.logging.log4j:log4j-slf4j-impl'
compile 'org.apache.logging.log4j:log4j-api'
compile 'org.apache.logging.log4j:log4j-core'
compile 'com.lmax:disruptor:3.3.4'

// This dependency is used by the application.
Expand Down
3 changes: 3 additions & 0 deletions src/org/minima/system/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.minima.system.brains.SendManager;
import org.minima.system.input.InputHandler;
import org.minima.system.network.NetworkHandler;
import org.minima.system.network.p2p.P2PMessageProcessor;
import org.minima.system.txpow.TxPoWMiner;
import org.minima.utils.MinimaLogger;
import org.minima.utils.SQLHandler;
Expand Down Expand Up @@ -249,6 +250,8 @@ protected void processMessage(Message zMessage) throws Exception {
}else if ( zMessage.isMessageType(SYSTEM_FULLSHUTDOWN) ) {

// todo stop p2pmanager
mNetwork.getP2PMessageProcessor().PostMessage(P2PMessageProcessor.P2P_SHUTDOWN);

//Savew ther UserPrefs
mUserPrefs.saveDB(mBackup.getUserPrefs());

Expand Down
8 changes: 4 additions & 4 deletions src/org/minima/system/network/NetworkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Enumeration;
import java.util.Random;

import lombok.extern.slf4j.Slf4j;
import org.minima.Start;
import org.minima.system.Main;
import org.minima.system.brains.ConsensusHandler;
Expand All @@ -30,7 +29,6 @@
import org.minima.utils.messages.MessageProcessor;
import org.minima.utils.messages.TimerMessage;

@Slf4j
public class NetworkHandler extends MessageProcessor {

public static final String NETWORK_STARTUP = "NETWORK_START";
Expand Down Expand Up @@ -142,6 +140,8 @@ public NetworkHandler(String zHost, int zMainPort, boolean fullNode) {
mLocalHost = zHost;
}

mLogON = true;

//Starts local
mIsRemoteOn = false;

Expand Down Expand Up @@ -443,7 +443,7 @@ protected void processMessage(Message zMessage) throws Exception {
MinimaClient client = (MinimaClient)zMessage.getObject("client");
boolean isIncoming = zMessage.getBoolean("isIncoming");

log.warn("[!!] NETWORK_NEWCLIENT " + client.getAddress());
MinimaLogger.log("[!!] NETWORK_NEWCLIENT " + client.getAddress());
//Add it
mClients.add(client);
// if (isIncoming) {
Expand Down Expand Up @@ -496,7 +496,7 @@ protected void processMessage(Message zMessage) throws Exception {

//Shut him down..
client.PostMessage(new Message(MinimaClient.NETCLIENT_SHUTDOWN));
log.warn("[!!] NETCLIENT_SHUTDOWN " + client);
MinimaLogger.log("[!!] NETCLIENT_SHUTDOWN " + client);

}else if(zMessage.isMessageType(NETWORK_TRACE)) {
boolean traceon = zMessage.getBoolean("trace");
Expand Down
4 changes: 4 additions & 0 deletions src/org/minima/system/network/base/MinimaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ public MinimaClient(InetSocketAddress address, NetworkHandler zNetwork) {
//Outgoing connection
mIncoming = false;

mLogON = true;

//Start the connection
PostMessage(NETCLIENT_INITCONNECT);
}
Expand Down Expand Up @@ -173,6 +175,8 @@ public MinimaClient(Socket zSock, NetworkHandler zNetwork) {
//Incoming connection
mIncoming = true;

mLogON = true;

//Start the system..
PostMessage(NETCLIENT_STARTUP);
}
Expand Down
71 changes: 40 additions & 31 deletions src/org/minima/system/network/base/MinimaReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.SocketException;
import java.util.ArrayList;

import org.minima.objects.TxPoW;
Expand All @@ -19,7 +21,13 @@
import org.minima.system.brains.ConsensusNet;
import org.minima.system.network.NetworkHandler;
import org.minima.system.network.p2p.P2PMessageProcessor;
import org.minima.system.network.p2p.messages.*;
import org.minima.system.network.p2p.messages.P2PMsgDoSwap;
import org.minima.system.network.p2p.messages.P2PMsgGreeting;
import org.minima.system.network.p2p.messages.P2PMsgNode;
import org.minima.system.network.p2p.messages.P2PMsgNodeNotAccepting;
import org.minima.system.network.p2p.messages.P2PMsgRendezvous;
import org.minima.system.network.p2p.messages.P2PMsgSwapLink;
import org.minima.system.network.p2p.messages.P2PMsgWalkLinks;
import org.minima.system.txpow.TxPoWChecker;
import org.minima.utils.Crypto;
import org.minima.utils.MiniFormat;
Expand Down Expand Up @@ -125,8 +133,8 @@ public void run() {
//The Consensus
ConsensusHandler consensus = Main.getMainHandler().getConsensusHandler();

while (!mNetClient.getSocket().isClosed()) {
try {
while (true) {
// try {
if (mInput.available() > 0) {
//What message type
msgtype = MiniByte.ReadFromStream(mInput);
Expand Down Expand Up @@ -346,17 +354,11 @@ public void run() {
Message msg = new Message(P2PMessageProcessor.P2P_NODE_NOT_ACCEPTING)
.addObject("data", data);
mNetClient.getNetworkHandler().getP2PMessageProcessor().PostMessage(msg);

}else {
//Unknown Message..
MinimaLogger.log("UNKNOWN MESSAGE MINIMAREADER.. "+msgtype);
}
// else {
// throw new Exception("Invalid message on network : " + rec);
// }

//Check there is nothing left..
// int left = inputstream.available();
// if (inputstream.available() > 0) {
// //Something gone wrong..
// throw new ProtocolException("Data left in inputstream when reading.. " + left);
// }

//Clean up..
inputstream.close();
Expand All @@ -365,25 +367,32 @@ public void run() {
//Post it..
consensus.PostMessage(rec);
}
} catch (ProtocolException exc) {
MinimaLogger.log("PROTOCOL ERROR.. " + exc);
MinimaLogger.log(exc);
} catch (OutOfMemoryError exc) {
MinimaLogger.log("MEMORY ERROR.. " + exc);
exc.printStackTrace();
//DRASTIC ACTION.. Use ONLY if bash script in place to restart on Exit
//System.exit(99);
} catch (Exception exc) {
//General Exception
MinimaLogger.log("NETCLIENTREADER ERROR.. ");
MinimaLogger.log(exc);
}
}
}catch (Exception exc) {
//General Exception
MinimaLogger.log("NETCLIENTREADER ERROR Client Disconnected.. ");
MinimaLogger.log(exc);
}

}catch(SocketException exc) {
//Network error.. reset and reconnect..
MinimaLogger.log("SocketException.. "+exc);
}catch(IOException exc) {
//Network error.. reset and reconnect..
MinimaLogger.log("IOEXC.. "+exc);
// exc.printStackTrace();

}catch(ProtocolException exc) {
MinimaLogger.log("PROTOCOL ERROR.. "+exc);
MinimaLogger.log(exc);

}catch(OutOfMemoryError exc) {
MinimaLogger.log("MEMORY ERROR.. "+exc);
exc.printStackTrace();

//DRASTIC ACTION.. Use ONLY if bash script in place to restart on Exit
//System.exit(99);

}catch(Exception exc) {
//General Exception
MinimaLogger.log("NETCLIENTREADER ERROR.. ");
MinimaLogger.log(exc);
}

//Tell the network Handler
mNetClient.getNetworkHandler().PostMessage(new Message(NetworkHandler.NETWORK_CLIENTERROR).addObject("client", mNetClient));
Expand Down
35 changes: 17 additions & 18 deletions src/org/minima/system/network/p2p/P2PMessageProcessor.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.minima.system.network.p2p;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.minima.GlobalParams;
import org.minima.objects.greet.Greeting;
import org.minima.system.Main;
Expand All @@ -11,6 +10,7 @@
import org.minima.system.network.base.MinimaClient;
import org.minima.system.network.p2p.functions.*;
import org.minima.system.network.p2p.messages.*;
import org.minima.utils.MinimaLogger;
import org.minima.utils.json.JSONArray;
import org.minima.utils.json.JSONObject;
import org.minima.utils.messages.Message;
Expand All @@ -34,7 +34,6 @@
import static org.minima.system.network.NetworkHandler.NETWORK_DISCONNECT;

@Getter
@Slf4j(topic = "P2P")
public class P2PMessageProcessor extends MessageProcessor {

/**
Expand Down Expand Up @@ -81,7 +80,7 @@ public P2PMessageProcessor() {
try {
this.hostIP = InetAddress.getByName("localhost");
} catch (UnknownHostException e) {
log.error("Could not identify the local ip address: " + hostIP);
MinimaLogger.log("Could not identify the local ip address: " + hostIP);
}
state = new P2PState(null);
state.setAddress(new InetSocketAddress(getHostIP(), getMinimaPort()));
Expand All @@ -95,7 +94,7 @@ public P2PMessageProcessor(String hostIP, int minimaPort) {
try {
this.hostIP = InetAddress.getByName(hostIP);
} catch (UnknownHostException e) {
log.error("Could not identify the local ip address: " + hostIP);
MinimaLogger.log("Could not identify the local ip address: " + hostIP);
}
this.minimaPort = minimaPort;

Expand Down Expand Up @@ -146,7 +145,7 @@ protected List<MinimaClient> getCurrentIncomingMinimaClientsOnMinimaPort() {
@Override
protected void processMessage(Message zMessage) throws Exception {
if (!zMessage.isMessageType(P2P_WALK_LINKS)) {
log.debug("[+] P2PMessageProcessor processing: " + zMessage.getMessageType());
MinimaLogger.log("[+] P2PMessageProcessor processing: " + zMessage.getMessageType());
}
try {
switch (zMessage.getMessageType()) {
Expand Down Expand Up @@ -214,7 +213,7 @@ protected void processMessage(Message zMessage) throws Exception {
for (StackTraceElement traceElement : trace)
builder.append("\tat ").append(traceElement).append("\n");

log.error("[!] Exception in P2P Message Processor: " + e + "\n" + builder);
MinimaLogger.log("[!] Exception in P2P Message Processor: " + e + "\n" + builder);
}
}

Expand All @@ -225,7 +224,7 @@ private void processSendMessage(Message zMessage) {
}

private void processShutdownMsg(Message zMessage) {
log.debug("[+] P2PMessageProcessor processing P2P_SHUTDOWN message");
MinimaLogger.log("[+] P2PMessageProcessor processing P2P_SHUTDOWN message");
// Make sure the node list is saved
StartupFuncs.SaveNodeList(this.state);
//And stop this Message Processor stack
Expand Down Expand Up @@ -262,10 +261,10 @@ private void processConnectMsg(Message zMessage) {

Message msg = new Message(NETWORK_CONNECT);
msg.addObject("address", address);
log.debug("[+] P2P_CONNECT to: " + address + " reason: " + reason);
MinimaLogger.log("[+] P2P_CONNECT to: " + address + " reason: " + reason);
Main.getMainHandler().getNetworkHandler().PostMessage(msg);
} else {
log.debug("[!] Attempting to connect to self");
MinimaLogger.log("[!] Attempting to connect to self");
state.removeRandomNodeSet(address);
}
}
Expand All @@ -274,7 +273,7 @@ private void processConnectMsg(Message zMessage) {
private void processOnDisconnectedMsg(Message zMessage) {
MinimaClient client = (MinimaClient) zMessage.getObject("client");
if (!client.isTemp()) {
log.debug("[!] P2P_ON_DISCONNECT Disconnected from isInLink? " + client.isIncoming() + " IP: " + client.getMinimaAddress());
MinimaLogger.log("[!] P2P_ON_DISCONNECT Disconnected from isInLink? " + client.isIncoming() + " IP: " + client.getMinimaAddress());
// Message walkMsg;
// if (client.isIncoming()) {
// walkMsg = DisconnectionFuncs.onInLinkDisconnected(state, client, getCurrentMinimaClients());
Expand All @@ -286,7 +285,7 @@ private void processOnDisconnectedMsg(Message zMessage) {
// }
state.removeDisconnectingClient(client.getUID());
state.removeLink(client);
log.debug(this.state.genPrintableState());
MinimaLogger.log(this.state.genPrintableState());
}

}
Expand All @@ -295,7 +294,7 @@ private void processOnDisconnectedMsg(Message zMessage) {
private void processDisconnectMsg(Message zMessage) {
MinimaClient client = (MinimaClient) zMessage.getObject("client");
String reason = zMessage.getString("reason");
log.debug("[!] P2P_DISCONNECT Disconnecting from isInLink? " + client.isIncoming() + " IP: " + client.getMinimaAddress() + " UID: " + client.getUID() + " for: " + reason);
MinimaLogger.log("[!] P2P_DISCONNECT Disconnecting from isInLink? " + client.isIncoming() + " IP: " + client.getMinimaAddress() + " UID: " + client.getUID() + " for: " + reason);
int attempt = zMessage.getInteger("attempt");
if (this.state.getOutLinks().contains(client.getMinimaAddress()) ||
this.state.getInLinks().contains(client.getMinimaAddress()) ||
Expand Down Expand Up @@ -354,7 +353,7 @@ public void processWalkLinksResponseMsg(Message zMessage) {
P2PMsgWalkLinks p2pWalkLinks = (P2PMsgWalkLinks) zMessage.getObject("data");
Message sendMsg = null;
if (state.getAddress().equals(p2pWalkLinks.getPathTaken().get(0))) {
log.debug("[+] P2P_WALK_LINKS_RESPONSE returned to origin node");
MinimaLogger.log("[+] P2P_WALK_LINKS_RESPONSE returned to origin node");
if (p2pWalkLinks.isClientWalk()) {
ArrayList<Message> msgs = WalkLinksFuncs.onReturnedClientWalkMsg(state, p2pWalkLinks);
msgs.forEach(this::PostMessage);
Expand Down Expand Up @@ -394,7 +393,7 @@ private void processLoopMsg(Message zMessage) {
}

ArrayList<ExpiringMessage> expiringMessages = this.state.dropExpiredMessages();
// log.debug(state.genPrintableState());
// MinimaLogger.log(state.genPrintableState());

PostTimerMessage(new TimerMessage(loopDelay, P2P_LOOP));
}
Expand All @@ -411,7 +410,7 @@ private void processNodeNotAcceptingMsgCheck() {
BroadcastFuncs.broadcastNodeNotAccepting(state, getCurrentMinimaClients())
.forEach(this::PostMessage);
state.setClient(true);
log.debug(state.genPrintableState());
MinimaLogger.log(state.genPrintableState());
}
}
PostTimerMessage(new TimerMessage(GlobalParams.P2P_NODE_NOT_ACCEPTING_CHECK_DELAY, P2P_NODE_NOT_ACCEPTING_CHECK));
Expand All @@ -424,7 +423,7 @@ private void processNodeNotAcceptingMsg(Message zMessage) {
P2PMsgNodeNotAccepting isClientMsg = (P2PMsgNodeNotAccepting) zMessage.getObject("data");
if (state.getInLinks().remove(isClientMsg.getBroadcaster())) {
state.getClientLinks().add(isClientMsg.getBroadcaster());
log.debug("[+] P2P_NODE_NOT_ACCEPTING_CHECK Moving " + isClientMsg.getBroadcaster() + " from inlinks to clientLinks");
MinimaLogger.log("[+] P2P_NODE_NOT_ACCEPTING_CHECK Moving " + isClientMsg.getBroadcaster() + " from inlinks to clientLinks");

}
}
Expand Down Expand Up @@ -456,7 +455,7 @@ private void processNetworkMapMsg(Message zMessage) {
if (state.getActiveMappingRequests().isEmpty()) {
PostMessage(new Message(P2P_PRINT_NETWORK_MAP_RESPONSE));
} else {
log.debug("[+] P2P_MAP_NETWORK active mappings left: " + state.getActiveMappingRequests().keySet());
MinimaLogger.log("[+] P2P_MAP_NETWORK active mappings left: " + state.getActiveMappingRequests().keySet());
}

PostMessage(new Message(P2PMessageProcessor.P2P_DISCONNECT)
Expand Down Expand Up @@ -516,7 +515,7 @@ private void processPrintNetworkMapResponseMsg(Message zMessage) {
InputHandler.endResponse(printNetworkMapRPCReq, true, "");

} else {
log.warn("[-] Failed to make network map");
MinimaLogger.log("[-] Failed to make network map");
}
}

Expand Down
Loading