Skip to content

Commit

Permalink
Merge pull request #318 from Junze888/develop
Browse files Browse the repository at this point in the history
refactor some code.
  • Loading branch information
LucasMLK committed May 20, 2024
2 parents 554771d + cf2cdaa commit fcc24fc
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,35 @@
</licenses>

<repositories>
<repository>
<id>bintray</id>
<url>https://jcenter.bintray.com</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>consensys-maven</id>
<url>https://artifacts.consensys.net/public/maven/maven/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>hyperledger.jfrog.io</id>
<url>https://hyperledger.jfrog.io/artifactory/besu-maven/</url>
</repository>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<pluginRepositories>
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/io/xdag/Kernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.xdag.net.*;
import io.xdag.net.message.MessageQueue;
import io.xdag.net.node.NodeManager;
import io.xdag.net.websocket.WebSocketServer;
import io.xdag.pool.PoolAwardManagerImpl;
import io.xdag.rpc.Web3;
import io.xdag.rpc.Web3Impl;
Expand Down Expand Up @@ -89,6 +90,7 @@ public class Kernel {

protected byte[] firstAccount;
protected Block firstBlock;
protected WebSocketServer webSocketServer;
protected PoolAwardManagerImpl poolAwardManager;
protected XdagState xdagState;

Expand Down Expand Up @@ -277,7 +279,7 @@ public synchronized void testStart() throws Exception {
// pow
// ====================================
pow = new XdagPow(this);

getWsServer().start();
log.info("Node to pool websocket start...");
// register pow
blockchain.registerListener(pow);
Expand Down Expand Up @@ -351,6 +353,14 @@ private Web3HttpServer getWeb3HttpServer() throws UnknownHostException {
return web3HttpServer;
}

public WebSocketServer getWsServer() {
if (webSocketServer == null) {
webSocketServer = new WebSocketServer(this, config.getPoolWhiteIPList(),
config.getWebsocketServerPort());
}
return webSocketServer;
}

private JsonRpcWeb3FilterHandler getJsonRpcWeb3FilterHandler() throws UnknownHostException {
if (jsonRpcWeb3FilterHandler == null) {
jsonRpcWeb3FilterHandler = new JsonRpcWeb3FilterHandler(
Expand Down Expand Up @@ -418,6 +428,8 @@ public synchronized void testStop() {
// release
randomx.randomXPoolReleaseMem();
log.info("Release randomx");
webSocketServer.stop();
log.info("WebSocket server stop.");
poolAwardManager.stop();
log.info("Pool award manager stop.");
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/xdag/config/AbstractConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public class AbstractConfig implements Config, AdminSpec, NodeSpec, WalletSpec,
protected int telnetPort = 7001;
protected String telnetPassword;

// =========================
// Pool websocket spec
// =========================

protected int websocketServerPort;

protected int maxShareCountPerChannel = 20;
protected int awardEpoch = 0xf;
protected int waitEpoch = 32;
Expand Down Expand Up @@ -246,6 +252,7 @@ public void getSetting() {

poolWhiteIPList = config.hasPath("pool.whiteIPs") ? config.getStringList("pool.whiteIPs") : Collections.singletonList("127.0.0.1");
log.info("Pool whitelist {}. Any IP allowed? {}", poolWhiteIPList, poolWhiteIPList.contains("0.0.0.0"));
websocketServerPort = config.hasPath("pool.ws.port") ? config.getInt("pool.ws.port") : 7001;
nodeIp = config.hasPath("node.ip") ? config.getString("node.ip") : "127.0.0.1";
nodePort = config.hasPath("node.port") ? config.getInt("node.port") : 8001;
nodeTag = config.hasPath("node.tag") ? config.getString("node.tag") : "xdagj";
Expand Down Expand Up @@ -382,6 +389,11 @@ public List<String> getPoolWhiteIPList() {
return poolWhiteIPList;
}

@Override
public int getWebsocketServerPort() {
return websocketServerPort;
}

@Override
public boolean isRPCEnabled() {
return rpcEnabled;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/xdag/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public interface Config {
//websocket
List<String> getPoolWhiteIPList();

int getWebsocketServerPort();

FundSpec getFundSpec();

}
18 changes: 16 additions & 2 deletions src/main/java/io/xdag/net/websocket/WebSocketServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.kqueue.KQueueEventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.util.NettyRuntime;
import io.xdag.Kernel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.SystemUtils;

import javax.annotation.Nullable;
import java.util.List;
Expand All @@ -48,8 +52,18 @@ public class WebSocketServer {
private final PoolHandShakeHandler poolHandShakeHandler;

public WebSocketServer(Kernel kernel, List<String> poolWhiteIPList, int port) {
this.bossGroup = new NioEventLoopGroup();
this.workerGroup = new NioEventLoopGroup();
int workerThreadPoolSize = NettyRuntime.availableProcessors() * 2;
if(SystemUtils.IS_OS_LINUX) {
this.bossGroup = new EpollEventLoopGroup();
this.workerGroup = new EpollEventLoopGroup(workerThreadPoolSize);
} else if(SystemUtils.IS_OS_MAC) {
this.bossGroup = new KQueueEventLoopGroup();
this.workerGroup = new KQueueEventLoopGroup(workerThreadPoolSize);

} else {
this.bossGroup = new NioEventLoopGroup();
this.workerGroup = new NioEventLoopGroup(workerThreadPoolSize);
}
this.poolHandShakeHandler = new PoolHandShakeHandler(kernel, poolWhiteIPList, port);
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/xdag-mainnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ rpc.http.host = 127.0.0.1
rpc.http.port = 10001
rpc.ws.port = 10002

# Miner Config
miner.globalMinerLimit = 8192
miner.globalMinerChannelLimit = 8192
miner.maxConnectPerIp = 256
miner.maxMinerPerAccount = 256

# Randomx Config
randomx.flags.fullmem = false

0 comments on commit fcc24fc

Please sign in to comment.