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

APL - 1676 nodeID #1111

Open
wants to merge 78 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
8adcf5c
Merge branch 'develop' into feature/APL-1676-node-id
Aug 19, 2020
1ae6cb8
Merge branch 'feature/APL-1671-fbcrypto-2.0' into feature/APL-1676-no…
Aug 20, 2020
71a9387
Merge branch 'feature/APL-1671-fbcrypto-2.0' into feature/APL-1676-no…
Aug 20, 2020
acd74d1
apl-id and apl-comm compilaton mdules added
Aug 21, 2020
0cdaa6e
Merge branch 'feature/APL-1676-node-id' of https://github.com/ApolloF…
Aug 21, 2020
d3e59bb
Merge branch 'feature/APL-1671-fbcrypto-2.0' into feature/APL-1676-no…
Aug 25, 2020
c8bf7cd
new FBCrypto on apl-bom-ext 1.0.2
Aug 25, 2020
1c29e7a
Merge branch 'develop' into feature/APL-1676-node-id
Aug 26, 2020
591fe0b
after-merge fix
Aug 26, 2020
8925f55
Merge branch 'develop' into feature/APL-1676-node-id
Aug 26, 2020
295c781
\Merge branch 'develop' into feature/APL-1676-node-id
Aug 27, 2020
8f6df59
generated sources deleted
Aug 28, 2020
7c3714b
Merge branch 'develop' into feature/APL-1676-node-id
Aug 28, 2020
873f617
Merge branch 'develop' into feature/APL-1676-node-id
Aug 28, 2020
564bb21
Merge branch 'feature/APL-1671-fbcrypto-2.0' into feature/APL-1676-no…
Aug 30, 2020
7dff970
delete of generated classes
Aug 31, 2020
30db0ef
Merge branch 'feature/APL-1676-node-id' of https://github.com/ApolloF…
Aug 31, 2020
db8eb79
APL-1676 node ID handler work in progress
Aug 31, 2020
624ec19
Merge branch 'feature/APL-1671-fbcrypto-2.0' into feature/APL-1676-no…
Aug 31, 2020
ce392f8
Merge branch 'feature/APL-1676-node-id' of https://github.com/ApolloF…
Sep 1, 2020
ca9c953
Merge branch 'feature/APL-1671-fbcrypto-2.0' into feature/APL-1676-no…
Sep 2, 2020
95b105e
cleanup of unneded stuff and fixes
Sep 2, 2020
d7c3943
hash of classed corrented
Sep 2, 2020
518856f
Apollo ID work in progress
Sep 4, 2020
f28cce6
Merge branch 'feature/APL-1676-node-id' of https://github.com/ApolloF…
Sep 4, 2020
530ce70
Merge branch 'develop' into feature/APL-1676-node-id
Sep 4, 2020
a0f82aa
Merge branch 'develop' into feature/APL-1676-node-id
Sep 4, 2020
a4a9ea1
Better class names
Sep 4, 2020
790d806
Better class and method names
Sep 4, 2020
90b5ec8
Id handler injected in peer http server
Sep 4, 2020
c8ec12e
better structure of identity handling
Sep 7, 2020
cd1bc66
Certificate - related code moved to security package of core
Sep 8, 2020
e4cd637
Merge branch 'develop' into feature/APL-1676-node-id
Sep 9, 2020
0d0873c
Merge branch 'develop' into feature/APL-1676-node-id
Sep 21, 2020
ac805cd
Merge branch 'develop' into feature/APL-1676-node-id
Sep 21, 2020
118f747
Moving all certificate-related stuff to the library
Sep 22, 2020
5fa75e4
X.509 identity handling is in separate llibrary
Sep 23, 2020
e850bf6
Object communication library now is separate project
Sep 23, 2020
476ff3a
Verions of fb-comm and fp-identity from apl-bom-ext 1.0.3
Sep 23, 2020
7388f86
compiation fix
Sep 23, 2020
a6fdd24
Fix of compilation with new libs
Sep 24, 2020
e188e00
PeerDao and PeerEntry update for ID support
Sep 29, 2020
b7604e6
PeerImpl add identity processing and some cleanup
Sep 29, 2020
40930cf
Merge branch 'develop' into feature/APL-1676-node-id
Sep 30, 2020
9f6e0ad
Fix of DB version update
Sep 30, 2020
5e7b8cb
DBMigrationExecutorTest disabled, see comments
Sep 30, 2020
5676e67
P2P code cleanup before big changes with ID handling
Oct 2, 2020
23aca7e
using fb-identity 1.0.1
Oct 8, 2020
6180fac
Merge branch 'develop' into feature/APL-1676-node-id
Oct 8, 2020
9efd77a
Merge branch 'develop' into feature/APL-1676-node-id
Oct 29, 2020
9cfba28
Merge branch 'develop' into feature/APL-1676-node-id
Oct 29, 2020
0512377
Merge branch 'develop' into feature/APL-1676-node-id
Nov 3, 2020
601b557
fix to fit new fb-identity interface
Nov 3, 2020
e5d6c02
Merge branch 'develop' into feature/APL-1676-node-id
Nov 12, 2020
a83b1e0
Merge branch 'develop' into feature/APL-1676-node-id
Nov 16, 2020
86ec2fd
Merge branch 'develop' into feature/APL-1676-node-id
Nov 21, 2020
e6ee4bb
Merge branch 'develop' into feature/APL-1676-node-id
Nov 25, 2020
5e46c0a
Merge branch 'develop' into feature/APL-1676-node-id
Nov 30, 2020
94e3f46
Merge branch 'develop' into feature/APL-1676-node-id
Dec 1, 2020
a8bcf14
Merge branch 'develop' into feature/APL-1676-node-id
Mar 24, 2021
f2ebd80
NodeId implementation is almost complete
alukin Mar 26, 2021
f41a9f2
PeerID feature implemented
alukin Mar 26, 2021
6bf2a1d
logs on PeerInfo set to trace
alukin Mar 26, 2021
3dc81e4
better processing of incoming certificates
Mar 26, 2021
5eb5a6e
ApolloWallet root certificate added; better impl of private key owner…
alukin Mar 29, 2021
dbd0181
Merge branch 'feature/APL-1676-node-id' of https://github.com/ApolloF…
alukin Mar 29, 2021
09d5b4c
better method naming
alukin Mar 29, 2021
0c17186
beans.xml added to modules
Mar 29, 2021
2b9c563
fix of application start; code cleanup
alukin Mar 30, 2021
b800460
Debug in progress
alukin Mar 31, 2021
63ecc54
debug mode is off; Node ID Feature is ready
alukin Mar 31, 2021
3f8aef2
Merge branch 'develop' into feature/APL-1676-node-id
alukin Mar 31, 2021
1f0b9d0
fix of NPE in transaction validation
alukin Apr 1, 2021
6b932c4
fix of NPE in transaction validation
alukin Apr 1, 2021
383ec9a
Merge branch 'develop' into feature/APL-1676-node-id
AndrewBoyarsky May 13, 2021
8b63905
Add apl-bom-ext proper version, move fb-identity version declaration …
AndrewBoyarsky May 13, 2021
a0af29f
Revert validation formatting, bump apl-bom-ext version (merged pr), m…
AndrewBoyarsky May 14, 2021
caad7ef
merged 'develop' branch
blandger May 15, 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 @@ -39,3 +39,4 @@ nbactions.xml
**/swagger-codegen-cli-*.jar
**/.swagger-codegen
/apl-api2/src/gen/
/apollo-mariadb
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,23 @@ public class PeerInfo extends BaseP2PResponse {
/**
* PEM-encoded X.509 Certificate of host as String, including
* BEGIN-CETIFICATE and END-CERTIFICATE marks. Certificate
* should be verified and used for private key cryptography. Certificate
* also contains some important attributes, that is used widely in communications.
* should be verified. CA-signed certificate should be verified using CA x.509 cert.
* Self-signed certificate should be verified by checking signature of "blockTime" field
* with proposed self-signed certificate to ensure private key ownership.
* New!
*/
private String X509_cert;
/**
* Epoch time of the node. Needed to approve private key ownership and make
* replay attacks less possible
*/
private Integer epochTime;
/**
* HEX string represenataion of the signature of blockTime (as 4 bytes in netowk order).
* Signature algorithm is the default for given public key type of X.509 certiificate,
* for more information please see fb-cryptoo library documentation
*/
private String epochTimeSigantureHex;
/**
* blacklist cause
*/
Expand Down
14 changes: 14 additions & 0 deletions apl-api/src/main/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:weld="http://jboss.org/schema/weld/beans"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
<decorators>
<class>org.jboss.weld.environment.se.threading.RunnableDecorator</class>
</decorators>
<weld:scan>
<weld:exclude name="org.jboss.weld.**" />
<weld:exclude name="io.swagger.**" />
</weld:scan>
</beans>
1 change: 1 addition & 0 deletions apl-api2/src/main/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
</decorators>
<weld:scan>
<weld:exclude name="org.jboss.weld.**" />
<weld:exclude name="io.swagger.**" />
</weld:scan>
</beans>
19 changes: 14 additions & 5 deletions apl-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@
<artifactId>apl-api2</artifactId>
<version>${project.version}</version>
</dependency>

<!-- EXT BOM DEPENDENCIES -->
<dependency>
<groupId>io.firstbridge</groupId>
<artifactId>fb-identity</artifactId>
<version>1.0.1</version>
AndrewBoyarsky marked this conversation as resolved.
Show resolved Hide resolved
<type>jar</type>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<dependency>
<groupId>com.apollocurrency</groupId>
<artifactId>apl-db-updater</artifactId>
Expand All @@ -51,11 +65,6 @@
<version>${project.version}</version>
</dependency>

<!-- EXT BOM DEPENDENCIES -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
* Copyright © 2018 Apollo Foundation
*/

package com.apollocurrency.aplwallet.apl.core.peer;
package com.apollocurrency.aplwallet.apl.core.dao.appdata;

import com.apollocurrency.aplwallet.apl.core.dao.TransactionalDataSource;
import com.apollocurrency.aplwallet.apl.core.entity.appdata.PeerEntity;
import com.apollocurrency.aplwallet.apl.core.peer.Peer;
import com.apollocurrency.aplwallet.apl.core.service.appdata.DatabaseManager;
import com.apollocurrency.aplwallet.apl.util.annotation.DatabaseSpecificDml;
import com.apollocurrency.aplwallet.apl.util.annotation.DmlMarker;
Expand All @@ -36,31 +38,42 @@
import java.util.List;

@Singleton
public class PeerDb {
public class PeerDao {

private final DatabaseManager databaseManager;

@Inject
public PeerDb(DatabaseManager databaseManagerParam) {
public PeerDao(DatabaseManager databaseManagerParam) {
databaseManager = databaseManagerParam;
}

public List<Entry> loadPeers() {
List<Entry> peers = new ArrayList<>();

public List<PeerEntity> loadPeers() {
List<PeerEntity> peers = new ArrayList<>();

TransactionalDataSource dataSource = databaseManager.getDataSource();
try (Connection con = dataSource.getConnection();
PreparedStatement pstmt = con.prepareStatement("SELECT * FROM peer");
ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) {
peers.add(new Entry(rs.getString("address"), rs.getLong("services"), rs.getInt("last_updated")));
peers.add(new PeerEntity(
rs.getString("address"),
rs.getLong("services"),
rs.getInt("last_updated"),
rs.getString("x509pem"),
rs.getString("ip_and_port")
)
);
}
} catch (SQLException e) {
throw new RuntimeException(e.toString(), e);
}
return peers;
}

public void deletePeer(Entry peer) {

public void deletePeer(PeerEntity peer) {

TransactionalDataSource dataSource = databaseManager.getDataSource();
try (Connection con = dataSource.getConnection()) {
PreparedStatement pstmt = con.prepareStatement("DELETE FROM peer WHERE address = ?");
Expand All @@ -71,11 +84,13 @@ public void deletePeer(Entry peer) {
}
}

public void deletePeers(Collection<Entry> peers) {

public void deletePeers(Collection<PeerEntity> peers) {

TransactionalDataSource dataSource = databaseManager.getDataSource();
try (Connection con = dataSource.getConnection();
PreparedStatement pstmt = con.prepareStatement("DELETE FROM peer WHERE address = ?")) {
for (Entry peer : peers) {
for (PeerEntity peer : peers) {
pstmt.setString(1, peer.getAddress());
pstmt.executeUpdate();
}
Expand All @@ -84,18 +99,20 @@ public void deletePeers(Collection<Entry> peers) {
}
}

public void updatePeers(Collection<Entry> peers) {
public void updatePeers(Collection<PeerEntity> peers) {

TransactionalDataSource dataSource = databaseManager.getDataSource();
dataSource.begin();
try (Connection con = dataSource.getConnection();
@DatabaseSpecificDml(DmlMarker.MERGE)

PreparedStatement pstmt = con.prepareStatement("INSERT INTO peer "
+ "(address, services, last_updated) "
+ "VALUES(?, ?, ?) "
+ "ON DUPLICATE KEY UPDATE "
+ "address = VALUES(address), services = VALUES(services), last_updated = VALUES(last_updated)")
) {
for (Entry peer : peers) {
for (PeerEntity peer : peers) {
pstmt.setString(1, peer.getAddress());
pstmt.setLong(2, peer.getServices());
pstmt.setInt(3, peer.getLastUpdated());
Expand All @@ -108,7 +125,9 @@ public void updatePeers(Collection<Entry> peers) {
}
}

public void updatePeer(PeerImpl peer) {

public void updatePeer(Peer peer) {

TransactionalDataSource dataSource = databaseManager.getDataSource();
dataSource.begin();
try (Connection con = dataSource.getConnection();
Expand All @@ -128,46 +147,4 @@ public void updatePeer(PeerImpl peer) {
}
}

static class Entry {
private final String address;
private final long services;
private final int lastUpdated;

Entry(String address, long services, int lastUpdated) {
this.address = address;
this.services = services;
this.lastUpdated = lastUpdated;
}

public String getAddress() {
return address;
}

public long getServices() {
return services;
}

public int getLastUpdated() {
return lastUpdated;
}

@Override
public int hashCode() {
return address.hashCode();
}

@Override
public boolean equals(Object obj) {
return (obj != null && (obj instanceof Entry) && address.equals(((Entry) obj).address));
}

@Override
public String toString() {
return "PeerEntry{" +
"address='" + address + '\'' +
", services=" + services +
", lastUpdated=" + lastUpdated +
'}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void init() {
@Named("publicKeyTable")
public EntityDbTableInterface<PublicKey> getPublicKeyTable() {
if (isCacheEnabled()) {
return new CachedTable<>(publicKeyCache, publicKeyTable);
return new CachedTable<>(publicKeyCache, publicKeyTable);
} else {
return publicKeyTable;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
* Copyright © 2019-2020 Apollo Foundation
*/
AndrewBoyarsky marked this conversation as resolved.
Show resolved Hide resolved
package com.apollocurrency.aplwallet.apl.core.entity.appdata;

import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright © 2019-2020 Apollo Foundation
*/
package com.apollocurrency.aplwallet.apl.core.entity.appdata;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
* DB record of known peer
*
* @author [email protected]
*/
@Data
@AllArgsConstructor
public class PeerEntity {

/**
* In previous version address is public IP, but now it could be IP:port or
* 256 bit identity in hexadecimal form
*/
private String address;
/**
* Services of node
*/
private long services;
/**
* time of last update in seconds
*/
private int lastUpdated;
/**
* X.509 certificate of node in PEM format
*/
private String x509pem;
/**
* Last seen on IP and port (IPv4 or IPv6)
*/
private String ipAndPort;
}
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ public static JSONObject peer(Peer peer) {
json.put("lastUpdated", peer.getLastUpdated());
json.put("lastConnectAttempt", peer.getLastConnectAttempt());
json.put("inbound", peer.isInbound());
json.put("inboundWebSocket", peer.isInboundSocket());
json.put("outboundWebSocket", peer.isOutboundSocket());
json.put("inboundWebSocket", peer.isInbound());
json.put("outboundWebSocket", peer.isOutbound());
if (peer.isBlacklisted()) {
json.put("blacklistingCause", peer.getBlacklistingCause());
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading