Skip to content

Commit

Permalink
Merge pull request #316 from LucasMLK/develop
Browse files Browse the repository at this point in the history
remove websocket and add jws-api dependency
  • Loading branch information
LucasMLK authored May 10, 2024
2 parents c225be0 + 6a355af commit 554771d
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 480 deletions.
12 changes: 7 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<mysql-connector.version>8.4.0</mysql-connector.version>
<h2.version>2.2.224</h2.version>
<gson.version>2.10</gson.version>
<jws-api.version>2.1.0</jws-api.version>
<surefire.test.excludes>**/*RandomXSyncTest.java,**/*SyncTest.java,**/*SnapshotJTest.java</surefire.test.excludes>
</properties>

Expand Down Expand Up @@ -370,7 +371,6 @@
</build>

<dependencies>
<!-- https://mvnrepository.com/artifact/io.xdag/xdagj-native-randomx -->
<dependency>
<groupId>io.xdag</groupId>
<artifactId>xdagj-native-randomx</artifactId>
Expand Down Expand Up @@ -796,7 +796,6 @@
<version>${jackson.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.github.briandilley.jsonrpc4j/jsonrpc4j -->
<dependency>
<groupId>com.github.briandilley.jsonrpc4j</groupId>
<artifactId>jsonrpc4j</artifactId>
Expand Down Expand Up @@ -850,22 +849,25 @@
</exclusions>
</dependency>

<dependency>
<groupId>jakarta.jws</groupId>
<artifactId>jakarta.jws-api</artifactId>
<version>${jws-api.version}</version>
</dependency>

<!--config-->
<!-- https://mvnrepository.com/artifact/com.typesafe/config -->
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>${config.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.agrona/agrona -->
<dependency>
<groupId>org.agrona</groupId>
<artifactId>agrona</artifactId>
<version>${agrona.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.xerial.snappy/snappy-java -->
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
Expand Down
46 changes: 1 addition & 45 deletions src/main/java/io/xdag/Kernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@
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;
import io.xdag.rpc.cors.CorsConfiguration;
import io.xdag.rpc.modules.xdag.*;
import io.xdag.rpc.netty.*;
import io.xdag.rpc.serialize.JacksonBasedRpcSerializer;
import io.xdag.rpc.serialize.JsonRpcSerializer;
import io.xdag.utils.XdagTime;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -92,7 +89,6 @@ public class Kernel {

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

Expand All @@ -112,10 +108,8 @@ public class Kernel {
// rpc
private JsonRpcWeb3ServerHandler jsonRpcWeb3ServerHandler;
private Web3 web3;
private Web3WebSocketServer web3WebSocketServer;
private Web3HttpServer web3HttpServer;
private JsonRpcWeb3FilterHandler jsonRpcWeb3FilterHandler;
private JacksonBasedRpcSerializer jacksonBasedRpcSerializer;

public Kernel(Config config, Wallet wallet) {
this.config = config;
Expand Down Expand Up @@ -283,7 +277,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 All @@ -300,7 +294,6 @@ public synchronized void testStart() throws Exception {
// ====================================
if (config.getRPCSpec().isRPCEnabled()) {
getWeb3HttpServer().start();
getWeb3WebSocketServer().start();
}

// ====================================
Expand Down Expand Up @@ -342,29 +335,6 @@ private JsonRpcWeb3ServerHandler getJsonRpcWeb3ServerHandler() {
return jsonRpcWeb3ServerHandler;
}

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

private Web3WebSocketServer getWeb3WebSocketServer() throws UnknownHostException {
if (web3WebSocketServer == null) {
JsonRpcSerializer jsonRpcSerializer = getJsonRpcSerializer();
XdagJsonRpcHandler jsonRpcHandler = new XdagJsonRpcHandler(jsonRpcSerializer);
web3WebSocketServer = new Web3WebSocketServer(
InetAddress.getByName(config.getRPCSpec().getRPCHost()),
config.getRPCSpec().getRPCPortByWebSocket(),
jsonRpcHandler,
getJsonRpcWeb3ServerHandler()
);
}

return web3WebSocketServer;
}

private Web3HttpServer getWeb3HttpServer() throws UnknownHostException {
if (web3HttpServer == null) {
web3HttpServer = new Web3HttpServer(
Expand Down Expand Up @@ -393,14 +363,6 @@ private JsonRpcWeb3FilterHandler getJsonRpcWeb3FilterHandler() throws UnknownHos
return jsonRpcWeb3FilterHandler;
}

private JsonRpcSerializer getJsonRpcSerializer() {
if (jacksonBasedRpcSerializer == null) {
jacksonBasedRpcSerializer = new JacksonBasedRpcSerializer();
}

return jacksonBasedRpcSerializer;
}

/**
* Stops the kernel.
*/
Expand All @@ -416,9 +378,6 @@ public synchronized void testStop() {
if (web3HttpServer != null) {
web3HttpServer.stop();
}
if (web3WebSocketServer != null) {
web3WebSocketServer.stop();
}

// 1. 工作层关闭
// stop consensus
Expand Down Expand Up @@ -459,13 +418,10 @@ 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.");
}


public enum Status {
STOPPED, SYNCING, BLOCK_PRODUCTION_ON, SYNCDONE
}
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/io/xdag/config/AbstractConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ 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 @@ -144,7 +138,6 @@ public class AbstractConfig implements Config, AdminSpec, NodeSpec, WalletSpec,
protected boolean rpcEnabled = false;
protected String rpcHost;
protected int rpcPortHttp;
protected int rpcPortWs;

// =========================
// Xdag Snapshot
Expand Down Expand Up @@ -253,7 +246,6 @@ 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 All @@ -277,7 +269,6 @@ public void getSetting() {
if (rpcEnabled) {
rpcHost = config.hasPath("rpc.http.host") ? config.getString("rpc.http.host") : "127.0.0.1";
rpcPortHttp = config.hasPath("rpc.http.port") ? config.getInt("rpc.http.port") : 10001;
rpcPortWs = config.hasPath("rpc.ws.port") ? config.getInt("rpc.ws.port") : 10002;
}
flag = config.hasPath("randomx.flags.fullmem") && config.getBoolean("randomx.flags.fullmem");

Expand Down Expand Up @@ -391,12 +382,6 @@ public List<String> getPoolWhiteIPList() {
return poolWhiteIPList;
}

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


@Override
public boolean isRPCEnabled() {
return rpcEnabled;
Expand All @@ -412,11 +397,6 @@ public int getRPCPortByHttp() {
return rpcPortHttp;
}

@Override
public int getRPCPortByWebSocket() {
return rpcPortWs;
}

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

int getWebsocketServerPort();

FundSpec getFundSpec();

}
1 change: 0 additions & 1 deletion src/main/java/io/xdag/config/spec/RPCSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ public interface RPCSpec {

int getRPCPortByHttp();

int getRPCPortByWebSocket();
}

This file was deleted.

102 changes: 0 additions & 102 deletions src/main/java/io/xdag/rpc/netty/Web3WebSocketServer.java

This file was deleted.

Loading

0 comments on commit 554771d

Please sign in to comment.