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

feat(net): merge release v2.0.0 into main #47

Merged
merged 188 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
2e2b1f0
add IPv6 support
317787106 Oct 31, 2022
0794db0
merge branch main
317787106 Oct 31, 2022
f92ed35
filter other IPstack in getNodes
317787106 Nov 2, 2022
d5537e0
start handshake
317787106 Nov 2, 2022
64708cc
use two map to drop same node in KadService
317787106 Nov 2, 2022
d4e534a
Merge branch 'main' into feature/ipv6
317787106 Nov 2, 2022
810e374
add log
317787106 Nov 4, 2022
b837194
merge main
317787106 Nov 7, 2022
324a6ed
get ipv6 from external url
317787106 Nov 7, 2022
d6eb542
don't setFinishHandshake when channel is active
317787106 Nov 8, 2022
eb8e33b
add IP stack Compatible testcase
317787106 Nov 9, 2022
94afc2f
optimize getNodeHandler; optimize getNodes; don't use timeout when ge…
317787106 Nov 10, 2022
a99ee49
prefer to send messgae by ipv4 in udp, though other node sends messag…
317787106 Nov 10, 2022
1a11370
remove comment
317787106 Nov 10, 2022
ff18d05
check if node is null in function addNode
317787106 Nov 11, 2022
0090e57
formar some code
317787106 Nov 11, 2022
97c5b83
merge two function
317787106 Nov 14, 2022
9212a82
optimize some code
317787106 Nov 14, 2022
4630360
optimize testcase NodeTest
317787106 Nov 14, 2022
0ab4739
merge main
317787106 Nov 16, 2022
21c4e97
Merge pull request #4 from tronprotocol/feature/ipv6
xxo1shine Nov 24, 2022
0f5baea
add node detect function
xxo1shine Nov 30, 2022
a82094e
remove the local debug logic
xxo1shine Nov 30, 2022
54060e0
add node detect trim map logic
xxo1shine Nov 30, 2022
422866e
optime node detect logic
xxo1shine Nov 30, 2022
744821d
modify upd new a node logic
xxo1shine Nov 30, 2022
d52641e
remove upd packet logic
xxo1shine Nov 30, 2022
92401a8
initial dns discover
317787106 Nov 30, 2022
d4e1fd5
modify channel init fuction
xxo1shine Nov 30, 2022
5b1e34a
use sender's ip when new node
317787106 Nov 30, 2022
a1a575f
Merge pull request #5 from tronprotocol/hotfix/no_lan_ipv4
xxo1shine Nov 30, 2022
33877a9
Merge branch 'develop' into feature/dns
317787106 Nov 30, 2022
d9a6c10
remove unuse log
xxo1shine Dec 1, 2022
5c4498c
add send and receive message log
xxo1shine Dec 1, 2022
185a0cb
message transmission supports compression function
xxo1shine Dec 6, 2022
ddd717b
add proto util test
xxo1shine Dec 6, 2022
911b318
set app version to 1
xxo1shine Dec 6, 2022
2f3da2f
add sync module
317787106 Dec 7, 2022
3e1067a
use proto EndPoints
317787106 Dec 8, 2022
d95f4c3
optimize some exception
317787106 Dec 9, 2022
2c0f440
Merge branch 'develop' into wk
xxo1shine Dec 12, 2022
66e8116
Merge pull request #7 from wubin01/wk
xxo1shine Dec 12, 2022
6e3744e
optimize exception
317787106 Dec 13, 2022
76eea9f
add dns publish service and alidns client
jwrct Dec 22, 2022
3419faa
delete key
jwrct Dec 22, 2022
70cb8cf
add aws dns publish
317787106 Dec 22, 2022
b69a67b
integrate aliyun and asw dns
317787106 Dec 22, 2022
c6c093e
update seq when deploy tree
317787106 Dec 22, 2022
8870ff8
improve DnsManager
317787106 Dec 22, 2022
4e52f46
extract publish in PublishService
317787106 Dec 23, 2022
45ff322
fix bug of AwsClient
317787106 Dec 23, 2022
38d2fcf
sign the tree again when seq changes
317787106 Dec 23, 2022
80e2ecd
merge kad and dns result in p2pservice; revise sync random node; merg…
317787106 Dec 27, 2022
61dbbb1
sumbit dns changes only if nodes changes's percent is bigger the thre…
317787106 Dec 27, 2022
1a7aab1
merge develop into feature/dns
317787106 Dec 27, 2022
c4d7592
update build.gradle
317787106 Dec 27, 2022
21eaf30
add public v4 and v6 dns server; don't sync the tree if seq or eroot …
317787106 Dec 28, 2022
fef1d66
use dns nodes in ConnPoolService; dynamic get nodes from dns when syn…
317787106 Dec 29, 2022
385777e
use proto DnsRoot to generate RootEntry
317787106 Dec 29, 2022
6403259
add proto DnsRoot
317787106 Dec 29, 2022
326a5fb
optimize Aliyun dns publish logic
jwrct Dec 30, 2022
94de304
fix bug of sync random
317787106 Dec 30, 2022
6996467
add usage of dns in StartApp
317787106 Jan 3, 2023
fc1f1af
optimize Aliyun dns publish logic
jwrct Jan 3, 2023
e3ef8a6
Merge branch 'feature/dns' of https://github.com/tronprotocol/java-p2…
jwrct Jan 3, 2023
a036955
merge code
jwrct Jan 3, 2023
8db4cdb
use Options to replace OptionGroup; decrease publishDelay
317787106 Jan 3, 2023
67caed6
add min-active-connection config in StartApp; modify cache expire to …
317787106 Jan 4, 2023
03a90fd
add paramater -h in StartApp
317787106 Jan 4, 2023
42b09dd
fix bug of help message
317787106 Jan 4, 2023
1ebf2ea
fix the bug of server nodes
317787106 Jan 4, 2023
93e0cab
add log if path is root in computeChanges
317787106 Jan 4, 2023
159a710
optimize some log
317787106 Jan 4, 2023
58de747
fix Aliyun dns publishing domain name issue
jwrct Jan 6, 2023
f9224aa
add PublishConfig; optimize getDnsNodes; don't sleep if fail too many…
317787106 Jan 6, 2023
32c73b6
Merge branch 'feature/dns' of https://github.com/tronprotocol/libp2p …
317787106 Jan 6, 2023
775072e
support publish seed nodes to dns when disable discovery
317787106 Jan 6, 2023
a032e8a
fix bug of test AwsRoute53Test
317787106 Jan 6, 2023
adbcdca
change Entry Prefix; change changeThreshold from 0.2 to 0.1;
317787106 Jan 9, 2023
5d0231c
fix bug of Tree
317787106 Jan 9, 2023
eb5740d
update two README.md document; update ImportUsing; log tree url when …
317787106 Jan 12, 2023
b9901ca
support invoking function of getRandomNodes concurrently
317787106 Jan 12, 2023
b57fbe1
get nodes from entries dynamically
317787106 Jan 13, 2023
081656d
add two example of dns; the server which only has ipv6 cannot publish…
317787106 Jan 30, 2023
05f4bb1
update version from 0.1.0 to 0.2.0
317787106 Jan 30, 2023
63aa8de
update proto HelloMessage,
317787106 Feb 2, 2023
2c3ee86
optimize P2pProtobufVarint32FrameDecoder log; change TCP_NETTY_WORK_T…
317787106 Feb 7, 2023
005b3d5
revert how to use libp2p.jar
317787106 Feb 7, 2023
342be42
Merge pull request #6 from tronprotocol/feature/dns
317787106 Feb 7, 2023
e80c96b
update README.md
317787106 Feb 7, 2023
f17ee3f
Merge pull request #11 from tronprotocol/feature/dns
317787106 Feb 7, 2023
cd30ce9
update README.md
317787106 Feb 7, 2023
21f993a
support libp2p automatic upgrade
xxo1shine Feb 8, 2023
75f311b
Merge branch 'develop' into libp2p_upgrade
xxo1shine Feb 8, 2023
d94b4e1
Merge pull request #13 from tronprotocol/libp2p_upgrade
xxo1shine Feb 8, 2023
f4377ac
give a random nodeID for dns node
317787106 Feb 8, 2023
cabbe75
Change log of P2pProtobufVarint32FrameDecoder; rename PacketDecoder t…
317787106 Feb 8, 2023
3f66c64
add home node to dnsnodes when publish
317787106 Feb 10, 2023
2f72a27
test LanIpV6
317787106 Feb 10, 2023
0b5090d
test testLanIpV6
317787106 Feb 10, 2023
f844a81
test testLanIpV6
317787106 Feb 10, 2023
4fa3c82
test testLanIpV6
317787106 Feb 10, 2023
2eda301
Use CopyOnWriteArrayList instead of ArrayList in P2pConfig
317787106 Feb 13, 2023
11a4267
add api testConnect for Publish
317787106 Feb 14, 2023
e4560d6
rename logback.xml to logback-libp2p.xml
317787106 Feb 14, 2023
09108de
filter used channel's InetSocketAddress
317787106 Feb 17, 2023
4778294
merge dns exception optimize
317787106 Feb 20, 2023
d66ff59
fix(dns): add more log
317787106 Feb 20, 2023
0c2fa74
Merge pull request #22 from tronprotocol/feature/dns
317787106 Feb 20, 2023
81a88e3
merge branch release_v0.1.3
317787106 Feb 20, 2023
bc11cbc
add blank line
317787106 Feb 20, 2023
6a35ace
format code
317787106 Feb 21, 2023
a62b19f
add some log
317787106 Feb 21, 2023
6734565
update README.md
317787106 Feb 21, 2023
8657e54
merge main into develop
317787106 Feb 21, 2023
6c8a4dc
merge main
317787106 Feb 22, 2023
d9fd739
Merge branch 'main' into merge_main
317787106 Feb 22, 2023
43140d4
update README.md
317787106 Feb 22, 2023
8b80281
update ConnPoolService
317787106 Feb 22, 2023
e4eb561
optimize active connection logic
jwrct Feb 22, 2023
15bf0e0
add integrity check section
jwrct Feb 22, 2023
f087304
Merge pull request #35 from chengtx01/update_readme
jwrct Feb 22, 2023
3ab7069
update ConnPoolService
317787106 Feb 22, 2023
7707109
update ConnPoolService
317787106 Feb 22, 2023
52968d8
merge release_v0.1.4
317787106 Feb 22, 2023
5b667f7
revert publish in build.gradle
317787106 Feb 22, 2023
6bc0377
solve the problem caused by activeNodes will change
jwrct Feb 23, 2023
d4b2779
Merge pull request #27 from tronprotocol/merge_main
317787106 Feb 24, 2023
712872f
add test log
jwrct Feb 24, 2023
d8ebd1d
merge develop
317787106 Feb 24, 2023
61de534
merge release_v0.1.4
317787106 Feb 24, 2023
96927a6
Merge branch 'develop' into feature/dns
317787106 Feb 24, 2023
36f6bb3
remove Region in some class
317787106 Feb 24, 2023
3c44e08
optimize the calculation of the count of lacking active connections
jwrct Feb 27, 2023
0545988
fix(net): exclude io.netty from software.amazon.awssdk
317787106 Mar 1, 2023
d3cbca2
add parameter staticNodes for PublishConfig
317787106 Mar 2, 2023
8b6bcea
add a test case testSubdomain
317787106 Mar 2, 2023
4769a01
optimize channel close logic
xxo1shine Mar 6, 2023
9b01429
Merge pull request #37 from wubin01/net
xxo1shine Mar 6, 2023
0a4f49f
if connot get ipv6 from IDENT_URL, we get if from network interface
317787106 Mar 6, 2023
b285765
filter local network ip from dns nodes
317787106 Mar 6, 2023
b695204
fix(net): fix the bug of getDnsNodes
317787106 Mar 6, 2023
73d0270
fix(net): revert ChannelManager HandshakeService
317787106 Mar 6, 2023
6d25f07
fix(net): optimize handMessage of ChannelManager
317787106 Mar 6, 2023
2281b99
delete unreachable dns server ip; fix the bug of empty data in proces…
317787106 Mar 7, 2023
2c9d4d2
change nodes from list to set
317787106 Mar 7, 2023
88bae9a
update README.md
317787106 Mar 7, 2023
5f82255
fix(net): disconnect with peer if reveive empty msg
317787106 Mar 7, 2023
2d5eafc
add debug log for aliyun publish
jwrct Mar 7, 2023
7f701e8
remove slow dns ip
317787106 Mar 7, 2023
c15cc9c
remove slow dns ip
317787106 Mar 7, 2023
42248de
fix(net): change some log
317787106 Mar 7, 2023
958e0e8
fix(db):filter homenode from active nodes; don't start discover serve…
317787106 Mar 9, 2023
46fc803
fix(db):remove paramater of nodemanager's init
317787106 Mar 9, 2023
cab811f
fix(db): remove some log
317787106 Mar 9, 2023
82cfc16
use node change percent in AliClient
317787106 Mar 13, 2023
a917dae
publish dns only once if publish static nodes
317787106 Mar 13, 2023
ec16da2
fix(net): clear serverNodes after deploy dns
317787106 Mar 13, 2023
ac7ff0f
fix(db): fix the bug of seq not change in AliClient
317787106 Mar 13, 2023
4de648e
Merge pull request #38 from tronprotocol/hotfix/aliyun_threshold
317787106 Mar 13, 2023
677b0b1
fix(net):use [ipv6]:port instead of ipv6:port
317787106 Mar 14, 2023
103ce76
Merge pull request #39 from tronprotocol/feature/ipv6
317787106 Mar 14, 2023
62d471c
fix(net): don't verify ip in parseInetSocketAddress
317787106 Mar 14, 2023
6000705
change root ttl for aliyun
jwrct Mar 14, 2023
149b0f2
fix(db): throw RuntimeException in parseInetSocketAddress of NetUtil
317787106 Mar 14, 2023
7549a1c
feat(net): add new api for P2pService
317787106 Mar 16, 2023
7524340
fix(net):don't close in ChannelManager if not init
317787106 Mar 20, 2023
4dc1084
fix(net): update logback-core from 1.2.3 to 1.2.9
317787106 Mar 20, 2023
58b4c94
fix(net): change some version of package to same with java-tron
317787106 Mar 20, 2023
1393d70
Merge branch 'release_v0.2.0' into develop_op_connect
jwrct Mar 20, 2023
f773d36
Merge pull request #34 from chengtx01/develop_op_connect
jwrct Mar 20, 2023
8f6caf2
Merge branch 'release_v0.2.0' into feature/channel_callback
317787106 Mar 20, 2023
c74e8eb
fix(net):use random nodeid if nodeid is null in connect
317787106 Mar 21, 2023
45b9574
fix(net): add parameter trigger for P2pChannelInitializer
317787106 Mar 22, 2023
8cf74ac
fix(net): remove unuseful annoation
317787106 Mar 22, 2023
fc96989
hotfix(net): use deprecate for connect
317787106 Mar 23, 2023
baaf5a8
packet decoding fails without printing the stack
xxo1shine Mar 28, 2023
cf765d4
fix the review problems
xxo1shine Mar 29, 2023
7931d27
fix(net): remove some log; change ttl
317787106 Mar 29, 2023
77fd0f3
change IOException to Exception
jwrct Mar 29, 2023
ce1fb1a
catch submit exception
jwrct Mar 29, 2023
632a659
Merge pull request #40 from tronprotocol/feature/channel_callback
317787106 Mar 29, 2023
7d6736c
Merge pull request #42 from chengtx01/develop_op_connect
jwrct Mar 29, 2023
e31e81a
feat(net): update io.grpc from 1.14.0 to 1.52.1
317787106 Apr 4, 2023
3ec4b3e
fix(net):update all io.grpc
317787106 Apr 6, 2023
3337f64
merge release_v0.1.5
317787106 Apr 6, 2023
c9cd115
Merge pull request #44 from tronprotocol/feature/update_grpc_v2
317787106 Apr 6, 2023
20c4553
fix(net): add error log in decode of MessageHandler
317787106 Apr 25, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ shareddata.*
/.settings/
/.apt_generated/

/src/test/java/org/tron/p2p/dns/PublishTest.java
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# libp2p
libp2p is a p2p network SDK implemented in java language. The functional modules that have been implemented so far include node discovery, connection management, and so on. Subsequent versions will implement more functions.
libp2p is a p2p network SDK implemented in java language. The functional modules that have been implemented so far include
* node discovery by p2p, include ipv4 and ipv6,
* tcp connection management,
* publish nodes on dns domain and node discovery by dns,
* support compressed message transmission among nodes

# Build
Building libp2p requires `git` and `Oracle JDK 1.8` to be installed, other JDK versions are not supported yet. Make sure you operate on `Linux` and `MacOS` operating systems.
Expand All @@ -25,7 +29,7 @@ then run the following command to start the node:
```bash
$ nohup java -jar libp2p.jar [options] >> start.log 2>&1 &
```
See the manual for details on [options](https://github.com/tronprotocol/libp2p/tree/main/src/main/java/org/tron/p2p/example/README.md)
See the manual for details on [options](https://github.com/tronprotocol/libp2p/tree/develop/src/main/java/org/tron/p2p/example/README.md)

## How to include the dependency
### Gradle Setting
Expand All @@ -39,32 +43,39 @@ repositories {
Then add the required packages as dependencies. Please add dependencies locally.
```bash
dependencies {
compile group: 'io.github.tronprotocol', name: 'libp2p', version: '0.1.4'
implementation group: 'io.github.tronprotocol', name: 'libp2p', version: '2.0.0'
}
```
Or if you are using the jar files as your dependencies:
```bash
dependencies {
compile fileTree(dir:'your path', include: '*.jar')
implementation fileTree(dir:'libs', include: 'libp2p.jar')
}
```

### Maven Setting
```bash
<repositories>
<repository>
<id>central-repos</id>
<repository>
<id>central-repos</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repository>
</repositories>

<dependency>
<groupId>io.github.tronprotocol</groupId>
<artifactId>libp2p</artifactId>
<version>0.1.4</version>
<groupId>io.github.tronprotocol</groupId>
<artifactId>libp2p</artifactId>
<version>2.0.0</version>
</dependency>
```

## Example
For some examples please check our [example package](https://github.com/tronprotocol/libp2p/tree/main/src/main/java/org/tron/p2p/example).
For some examples please check our [example package](https://github.com/tronprotocol/libp2p/tree/develop/src/main/java/org/tron/p2p/example).

# Integrity Check
* After February 21, 2023, releases are signed the gpg key:
```
pub: 1254 F859 D2B1 BD9F 66E7 107D F859 BCB4 4A28 290B
uid: build@tron.network
```
94 changes: 24 additions & 70 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'io.github.tronprotocol'
version '0.1.5'
version '2.0.0'

buildscript {
repositories {
Expand All @@ -16,12 +16,8 @@ apply plugin: 'java'
apply plugin: 'com.google.protobuf'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'application'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: "io.github.gradle-nexus.publish-plugin"

def protobufVersion = "3.21.12"

def grpcVersion = "1.52.1"

mainClassName = 'org.tron.p2p.example.StartApp'
Expand Down Expand Up @@ -60,19 +56,37 @@ buildscript {
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'

implementation group: 'org.xerial.snappy', name: 'snappy-java', version: '1.1.8.4'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.9'
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.3'
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.9'
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: protobufVersion
implementation group: 'com.google.protobuf', name: 'protobuf-java-util', version: protobufVersion
implementation group: 'io.grpc', name: 'grpc-netty', version: grpcVersion
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: '1.69'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
implementation group: 'commons-cli', name: 'commons-cli', version: '1.5.0'

compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.24'
testImplementation group: 'org.projectlombok', name: 'lombok', version: '1.18.24'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.24'
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.12'
testImplementation group: 'org.projectlombok', name: 'lombok', version: '1.18.12'
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.12'

implementation group: 'dnsjava', name: 'dnsjava', version: '3.5.2'
implementation group: 'org.web3j', name: 'crypto', version: '5.0.0'
implementation('software.amazon.awssdk:route53:2.18.41', {
exclude group: 'io.netty', module: 'netty-codec-http2'
exclude group: 'io.netty', module: 'netty-codec-http'
exclude group: 'io.netty', module: 'netty-common'
exclude group: 'io.netty', module: 'netty-buffer'
exclude group: 'io.netty', module: 'netty-transport'
exclude group: 'io.netty', module: 'netty-codec'
exclude group: 'io.netty', module: 'netty-handler'
exclude group: 'io.netty', module: 'netty-resolver'
exclude group: 'io.netty', module: 'netty-transport-classes-epoll'
exclude group: 'io.netty', module: 'netty-transport-native-unix-common'
})
implementation group: 'com.aliyun', name: 'alidns20150109', version: '3.0.1'
implementation group: 'xerces', name: 'xercesImpl', version: '2.11.0'
}

tasks.matching { it instanceof Test }.all {
Expand Down Expand Up @@ -158,64 +172,4 @@ artifacts {
archives javadocJar, sourcesJar
}

publishing {

publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
pom {
name = 'libp2p'
description = 'libp2p is a p2p network SDK implemented in java language.'
url = 'https://github.com/tronprotocol/libp2p'
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
name = 'chengtx01'
email = 'ctxhorse@gmail.com'
}
developer {
name = 'jiangyuanshu'
email = '317787106@qq.com'
}
developer {
name = 'wubin01'
email = 'wb_bupt@163.com'
}
}
scm {
url = 'https://github.com/tronprotocol/libp2p'
connection = 'scm:git:git://github.com/tronprotocol/libp2p.git'
developerConnection = 'scm:git:ssh://git@github.com:tronprotocol/libp2p.git'
}
}
}
}
}

nexusPublishing {
repositories {
sonatype {
//only for users registered in Sonatype after 24 Feb 2021
nexusUrl = uri("https://s01.oss.sonatype.org/service/local/")
snapshotRepositoryUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
username = "${sonatypeUsername}"
password = "${sonatypePassword}"
}
}
}


signing {
// https://discuss.gradle.org/t/use-of-signing-plugin-with-gpg-agent-fails-with-gradle-5-x/38351/2
useGpgCmd()
sign publishing.publications.mavenJava
}


15 changes: 13 additions & 2 deletions src/main/java/org/tron/p2p/P2pConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,35 @@

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import lombok.Data;
import org.tron.p2p.dns.update.PublishConfig;
import org.tron.p2p.utils.NetUtil;

@Data
public class P2pConfig {

private List<InetSocketAddress> seedNodes = new CopyOnWriteArrayList<>();
private List<InetSocketAddress> activeNodes = new CopyOnWriteArrayList<>();
private List<InetAddress> trustNodes = new CopyOnWriteArrayList<>();
private byte[] nodeID = NetUtil.getNodeId();
private String ip = NetUtil.getExternalIp();
private String ip = NetUtil.getExternalIpV4();
private String ipv6 = NetUtil.getExternalIpV6();
private int port = 18888;
private int version = 1;
private int networkId = 1;
private int minConnections = 8;
private int maxConnections = 50;
private int minActiveConnections = 2;
private int maxConnectionsWithSameIp = 2;
private boolean discoverEnable = true;
private boolean disconnectionPolicyEnable = false;
private boolean nodeDetectEnable = false;

//dns read config
private List<String> treeUrls = new ArrayList<>();

//dns publish config
private PublishConfig publishConfig = new PublishConfig();
}
26 changes: 24 additions & 2 deletions src/main/java/org/tron/p2p/P2pService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package org.tron.p2p;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.tron.p2p.base.Parameter;
import org.tron.p2p.connection.Channel;
import org.tron.p2p.connection.ChannelManager;
import org.tron.p2p.discover.Node;
import org.tron.p2p.discover.NodeManager;
import org.tron.p2p.dns.DnsManager;
import org.tron.p2p.exception.P2pException;
import org.tron.p2p.stats.P2pStats;
import org.tron.p2p.stats.StatsManager;
Expand All @@ -21,10 +27,12 @@ public void start(P2pConfig p2pConfig) {
Parameter.p2pConfig = p2pConfig;
NodeManager.init();
ChannelManager.init();
DnsManager.init();
log.info("P2p service started");
}

public void close() {
DnsManager.close();
NodeManager.close();
ChannelManager.close();
log.info("P2p service closed");
Expand All @@ -34,10 +42,15 @@ public void register(P2pEventHandler p2PEventHandler) throws P2pException {
Parameter.addP2pEventHandle(p2PEventHandler);
}

@Deprecated
public void connect(InetSocketAddress address) {
ChannelManager.connect(address);
}

public ChannelFuture connect(Node node, ChannelFutureListener future) {
return ChannelManager.connect(node, future);
}

public P2pStats getP2pStats() {
return statsManager.getP2pStats();
}
Expand All @@ -47,15 +60,24 @@ public List<Node> getTableNodes() {
}

public List<Node> getConnectableNodes() {
return NodeManager.getConnectableNodes();
Set<Node> nodes = new HashSet<>();
nodes.addAll(NodeManager.getConnectableNodes());
nodes.addAll(DnsManager.getDnsNodes());
return new ArrayList<>(nodes);
}

public List<Node> getAllNodes() {
return NodeManager.getAllNodes();
Set<Node> nodes = new HashSet<>();
nodes.addAll(NodeManager.getAllNodes());
nodes.addAll(DnsManager.getDnsNodes());
return new ArrayList<>(nodes);
}

public void updateNodeId(Channel channel, String nodeId) {
ChannelManager.updateNodeId(channel, nodeId);
}

public int getVersion() {
return Parameter.version;
}
}
5 changes: 3 additions & 2 deletions src/main/java/org/tron/p2p/base/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
public class Constant {

public static final int NODE_ID_LEN = 64;

public static final String AMAZONAWS_URL = "http://checkip.amazonaws.com";

public static final String IDENT_URL = "https://v6.ident.me";
public static final String ipV4Hex = "00000000"; //32 bit
public static final String ipV6Hex = "00000000000000000000000000000000"; //128 bit
}
22 changes: 22 additions & 0 deletions src/main/java/org/tron/p2p/base/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.protobuf.ByteString;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.tron.p2p.P2pConfig;
import org.tron.p2p.P2pEventHandler;
import org.tron.p2p.exception.P2pException;
import org.tron.p2p.exception.P2pException.TypeEnum;
import org.tron.p2p.protos.Discover;
import org.tron.p2p.utils.ByteArray;

@Data
public class Parameter {

public static int version = 1;

public static final int TCP_NETTY_WORK_THREAD_NUM = 0;

public static final int UDP_NETTY_WORK_THREAD_NUM = 1;
Expand Down Expand Up @@ -46,4 +53,19 @@ public static void addP2pEventHandle(P2pEventHandler p2PEventHandler) throws P2p
}
handlerList.add(p2PEventHandler);
}

public static Discover.Endpoint getHomeNode() {
Discover.Endpoint.Builder builder = Discover.Endpoint.newBuilder()
.setNodeId(ByteString.copyFrom(Parameter.p2pConfig.getNodeID()))
.setPort(Parameter.p2pConfig.getPort());
if (StringUtils.isNotEmpty(Parameter.p2pConfig.getIp())) {
builder.setAddress(ByteString.copyFrom(
ByteArray.fromString(Parameter.p2pConfig.getIp())));
}
if (StringUtils.isNotEmpty(Parameter.p2pConfig.getIpv6())) {
builder.setAddressIpv6(ByteString.copyFrom(
ByteArray.fromString(Parameter.p2pConfig.getIpv6())));
}
return builder.build();
}
}
Loading