Skip to content

Commit

Permalink
defined fields in terms of interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aionick committed May 25, 2018
1 parent f31e6ba commit 1d48630
Show file tree
Hide file tree
Showing 18 changed files with 331 additions and 113 deletions.
64 changes: 64 additions & 0 deletions modAionImpl/test/org/aion/zero/impl/sync/BlockPropagationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.google.common.truth.Truth.assertThat;

import java.io.IOException;
import java.math.BigInteger;
import java.nio.channels.SocketChannel;
import java.util.*;
Expand Down Expand Up @@ -81,6 +82,42 @@ public long getTimestamp() {
public String getBinaryVersion() {
return "";
}

@Override
public void setPort(int _port) { throw new IllegalStateException("not implemented"); }

@Override
public void setConnection(String _connection) { throw new IllegalStateException("not implemented"); }

@Override
public IPeerMetric getPeerMetric() { throw new IllegalStateException("not implemented"); }

@Override
public void refreshTimestamp() { throw new IllegalStateException("not implemented"); }

@Override
public void setChannel(SocketChannel _channel) { throw new IllegalStateException("not implemented"); }

@Override
public void setId(byte[] _id) { throw new IllegalStateException("not implemented"); }

@Override
public void setBinaryVersion(String _revision) { throw new IllegalStateException("not implemented"); }

@Override
public boolean getIfFromBootList() { throw new IllegalStateException("not implemented"); }

@Override
public byte[] getBestBlockHash() { throw new IllegalStateException("not implemented"); }

@Override
public String getConnection() { throw new IllegalStateException("not implemented"); }

@Override
public SocketChannel getChannel() { throw new IllegalStateException("not implemented"); }

@Override
public void setFromBootList(boolean _ifBoot) { throw new IllegalStateException("not implemented"); }
}

private static class P2pMock implements IP2pMgr {
Expand Down Expand Up @@ -138,6 +175,33 @@ public void closeSocket(SocketChannel _sc, String _reason) {}
public int getSelfIdHash() {
return 0;
}

@Override
public void dropActive(int _nodeIdHash, String _reason) { throw new IllegalStateException("not implemented."); }

@Override
public void configChannel(SocketChannel _channel) {
throw new IllegalStateException("not implemented.");
}

@Override
public int getMaxActiveNodes() { throw new IllegalStateException("not implemented."); }

@Override
public boolean isSyncSeedsOnly() { throw new IllegalStateException("not implemented."); }

@Override
public int getTxBroadCastRoute() { throw new IllegalStateException("not implemented."); }

@Override
public int getMaxTempNodes() { throw new IllegalStateException("not implemented."); }

@Override
public boolean validateNode(INode _node) { throw new IllegalStateException("not implemented."); }

@Override
public int getSelfNetId() { throw new IllegalStateException("not implemented."); }

}

private static List<ECKey> generateDefaultAccounts() {
Expand Down
26 changes: 26 additions & 0 deletions modP2p/src/org/aion/p2p/INode.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package org.aion.p2p;

import java.math.BigInteger;
import java.nio.channels.SocketChannel;

/**
*
Expand Down Expand Up @@ -84,4 +85,29 @@ public interface INode {
void updateStatus(long _bestBlockNumber, final byte[] _bestBlockHash, BigInteger _totalDifficulty);

String getBinaryVersion();

boolean getIfFromBootList();

byte[] getBestBlockHash();

String getConnection();

SocketChannel getChannel();

void setFromBootList(boolean _ifBoot);

void setConnection(String _connection);

IPeerMetric getPeerMetric();

void refreshTimestamp();

void setChannel(SocketChannel _channel);

void setId(byte[] _id);

void setPort(int _port);

void setBinaryVersion(String _revision);

}
45 changes: 45 additions & 0 deletions modP2p/src/org/aion/p2p/INodeMgr.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.aion.p2p;

import java.util.List;
import java.util.Map;

public interface INodeMgr {

void timeoutActive(final IP2pMgr _p2pMgr);
Expand All @@ -10,4 +13,46 @@ public interface INodeMgr {

void dropActive(int _nodeIdHash, final IP2pMgr _p2pMgr, String _reason);

void timeoutInbound(IP2pMgr _p2pMgr);

Map<Integer, INode> getOutboundNodes();

int activeNodesSize();

INode tempNodesTake() throws InterruptedException;

boolean isSeedIp(String _ip);

void addTempNode(INode _n);

boolean hasActiveNode(int k);

void addOutboundNode(INode _n);

void addInboundNode(INode _n);

INode allocNode(String ip, int p0);

INode getActiveNode(int k);

List<INode> getActiveNodesList();

int tempNodesSize();

INode getInboundNode(int k);

INode getOutboundNode(int k);

String dumpNodeInfo(String selfShortId);

void seedIpAdd(String _ip);

void shutdown(IP2pMgr _p2pMgr);

void ban(int _nodeIdHash);

INode getRandom();

Map<Integer, INode> getActiveNodesMap();

}
17 changes: 17 additions & 0 deletions modP2p/src/org/aion/p2p/IP2pMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package org.aion.p2p;

import java.io.IOException;
import java.nio.channels.SocketChannel;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -64,4 +65,20 @@ public interface IP2pMgr {
boolean isShowLog();

void errCheck(int nodeIdHashcode, String _displayId);

void dropActive(int _nodeIdHash, String _reason);

void configChannel(SocketChannel _channel) throws IOException;

int getMaxActiveNodes();

boolean isSyncSeedsOnly();

int getTxBroadCastRoute();

int getMaxTempNodes();

boolean validateNode(INode _node);

int getSelfNetId();
}
15 changes: 15 additions & 0 deletions modP2p/src/org/aion/p2p/IPeerMetric.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.aion.p2p;

public interface IPeerMetric {

boolean shouldNotConn();

void incFailedCount();

void decFailedCount();

void ban();

boolean notBan();

}
25 changes: 21 additions & 4 deletions modP2pImpl/src/org/aion/p2p/impl/comm/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Arrays;
import java.util.regex.Pattern;
import org.aion.p2p.INode;
import org.aion.p2p.IPeerMetric;

/*
*
Expand Down Expand Up @@ -88,7 +89,12 @@ public final class Node implements INode {
*/
private String connection = "";

public PeerMetric peerMetric = new PeerMetric();
public IPeerMetric peerMetric = new PeerMetric();

@Override
public IPeerMetric getPeerMetric() {
return this.peerMetric;
}

/**
* constructor for initial stage of connections from network
Expand Down Expand Up @@ -182,6 +188,7 @@ public static Node parseP2p(String _p2p) {
return new Node(true, _id, _ip, _port);
}

@Override
public void setFromBootList(boolean _ifBoot) {
this.fromBootList = _ifBoot;
}
Expand All @@ -190,6 +197,7 @@ public void setFromBootList(boolean _ifBoot) {
* @param _id
* byte[]
*/
@Override
public void setId(final byte[] _id) {
this.id = _id;
if (_id != null && _id.length == 36) {
Expand All @@ -202,10 +210,12 @@ public void setId(final byte[] _id) {
* @param _port
* int
*/
@Override
public void setPort(final int _port) {
this.port = _port;
}

@Override
public void setBinaryVersion(String _revision) {
this.binaryVersion = _revision;
}
Expand All @@ -214,6 +224,7 @@ public void setBinaryVersion(String _revision) {
* this method used to keep current node stage on either pending list or active
* list
*/
@Override
public void refreshTimestamp() {
this.timestamp = System.currentTimeMillis();
}
Expand All @@ -222,6 +233,7 @@ public void refreshTimestamp() {
* @param _channel
* SocketChannel
*/
@Override
public void setChannel(final SocketChannel _channel) {
this.channel = _channel;
}
Expand All @@ -230,13 +242,15 @@ public void setChannel(final SocketChannel _channel) {
* @param _connection
* String
*/
void setConnection(String _connection) {
@Override
public void setConnection(String _connection) {
this.connection = _connection;
}

/**
* @return boolean
*/
@Override
public boolean getIfFromBootList() {
return this.fromBootList;
}
Expand Down Expand Up @@ -270,6 +284,7 @@ public String getBinaryVersion() {
/**
* @return SocketChannel
*/
@Override
public SocketChannel getChannel() {
return this.channel;
}
Expand All @@ -287,7 +302,8 @@ public int getIdHash() {
/**
* @return String
*/
String getConnection() {
@Override
public String getConnection() {
return this.connection;
}

Expand All @@ -301,7 +317,8 @@ public long getBestBlockNumber() {
return this.bestBlockNumber;
}

byte[] getBestBlockHash() {
@Override
public byte[] getBestBlockHash() {
return this.bestBlockHash;
}

Expand Down
Loading

0 comments on commit 1d48630

Please sign in to comment.