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

Add a variable to specify if this is an incoming or outgoing connection #339

Merged
merged 1 commit into from
Jul 15, 2021
Merged
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
28 changes: 26 additions & 2 deletions src/org/minima/system/network/base/MinimaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class MinimaClient extends MessageProcessor {
//The Host and Port
String mHost;
int mPort;
int mLocalPort;

//Ping each other to know you are still up and running.. every 10 mins..
public static final int PING_INTERVAL = 1000 * 60 * 10;
Expand All @@ -89,7 +90,12 @@ public class MinimaClient extends MessageProcessor {
boolean mReconnect = false;
int mReconnectAttempts = 0;

/**
/**
* Incoming or Outgoing
*/
boolean mIncoming;

/**
* Constructor
*
* @param zSock
Expand Down Expand Up @@ -117,6 +123,7 @@ public MinimaClient(String zHost, int zPort, NetworkHandler zNetwork) {
//Store
mHost = zHost;
mPort = zPort;
mLocalPort = zPort;

//We will attempt to reconnect if this connection breaks..
mReconnect = true;
Expand All @@ -127,6 +134,9 @@ public MinimaClient(String zHost, int zPort, NetworkHandler zNetwork) {
//Create a UID
mUID = ""+Math.abs(new Random().nextInt());

//Outgoing connection
mIncoming = false;

//Start the connection
PostMessage(NETCLIENT_INITCONNECT);
}
Expand All @@ -136,20 +146,24 @@ public MinimaClient(Socket zSock, NetworkHandler zNetwork) {

//This is an incoming connection.. no reconnect attempt
mReconnect = false;

//Store
mSocket = zSock;

//Store
mHost = mSocket.getInetAddress().getHostAddress();
mPort = mSocket.getPort();
mLocalPort = mSocket.getLocalPort();

//Main network Handler
mNetworkMain = zNetwork;

//Create a UID
mUID = ""+Math.abs(new Random().nextInt());

//Incoming connection
mIncoming = true;

//Start the system..
PostMessage(NETCLIENT_STARTUP);
}
Expand Down Expand Up @@ -178,6 +192,14 @@ public String getUID() {
return mUID;
}

public boolean isIncoming() {
return mIncoming;
}

public int getLocalPort() {
return mLocalPort;
}

public String getNodeID() {
return nodeID;
}
Expand All @@ -196,6 +218,8 @@ public JSONObject toJSON() {
ret.put("uid", mUID);
ret.put("host", getHost());
ret.put("port", getPort());
ret.put("localport", getLocalPort());
ret.put("incoming", mIncoming);

return ret;
}
Expand Down