Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Use NodeKey instead of ECKey in Channel class
Browse files Browse the repository at this point in the history
NodeKey is a wrapper around ECKey that does allow comparing the same
ECKey. ECKey.equals is generally not reliable, as it also compares the
createDate of the key.
  • Loading branch information
matsjj committed May 26, 2016
1 parent 7f4487d commit 2494191
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public PaymentWrapper fromString (String string) {
@Override
public String toString (Channel channel) {
return Coin.valueOf(channel.channelStatus.amountServer).toFriendlyString() +
" with " + model.getHostname(Main.dbHandler.getIPObjects(), channel.nodeKeyClient);
" with " + model.getHostname(Main.dbHandler.getIPObjects(), channel.nodeKeyClient.getPubKey());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static void main (String[] args) throws Exception {
buildChannelListener.await(30, TimeUnit.SECONDS);
List<Channel> openChannel = dbHandler.getOpenChannel();
for (Channel channel : openChannel) {
configuration.nodesToBuildChannelWith.add(Tools.bytesToHex(channel.nodeKeyClient));
configuration.nodesToBuildChannelWith.add(channel.nodeKeyClient.getPubKeyHex());
}
writeConfigurationFile(configuration);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
public class ClientObject {
public boolean isServer;

//TODO transition to NodeKey.class
public ECKey pubKeyClient;
public NodeKey nodeKey;

//Encryption keys
public ECKey ephemeralKeyServer;
Expand Down Expand Up @@ -50,7 +49,7 @@ public ClientObject (ClientObject node) {
init();
this.port = node.port;
this.host = node.host;
this.pubKeyClient = node.pubKeyClient;
this.nodeKey = node.nodeKey;
this.isServer = node.isServer;
this.intent = node.intent;
this.name = node.name;
Expand All @@ -64,12 +63,11 @@ public ClientObject (ServerObject node) {
init();
this.host = node.hostServer;
this.port = node.portServer;
this.pubKeyClient = node.pubKeyServer;
this.nodeKey = new NodeKey(node.pubKeyServer);
this.isServer = false;
}

public void init () {
pubKeyClient = new ECKey();
ephemeralKeyServer = new ECKey();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import network.thunder.core.helper.callback.SyncListener;
import network.thunder.core.helper.callback.results.*;
import network.thunder.core.helper.events.LNEventHelper;
import org.bitcoinj.core.ECKey;
import org.eclipse.jetty.util.BlockingArrayQueue;

import java.util.ArrayList;
Expand Down Expand Up @@ -245,7 +244,7 @@ public void startBuildingRandomChannel (ResultCommand callback) {
System.out.println("BUILD CHANNEL WITH: " + randomNode);

ClientObject node = ipObjectToNode(randomNode, OPEN_CHANNEL);
channelManager.openChannel(new NodeKey(node.pubKeyClient), new ChannelOpenListener());
channelManager.openChannel(node.nodeKey, new ChannelOpenListener());

alreadyTried.add(randomNode);

Expand Down Expand Up @@ -313,7 +312,7 @@ private ClientObject ipObjectToNode (PubkeyIPObject ipObject, ConnectionIntent i
ClientObject node = new ClientObject();
node.isServer = false;
node.intent = intent;
node.pubKeyClient = ECKey.fromPublicOnly(ipObject.pubkey);
node.nodeKey = new NodeKey(ipObject.pubkey);
node.host = ipObject.hostname;
node.port = ipObject.port;
return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public ServerObject (ClientObject node) {
init();
this.portServer = node.port;
this.hostServer = node.host;
this.pubKeyServer = node.pubKeyClient;
this.pubKeyServer = node.nodeKey.nodeKey;
}

public ServerObject () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import network.thunder.core.communication.ClientObject;
import network.thunder.core.communication.Connection;
import network.thunder.core.communication.ConnectionRegistry;
import network.thunder.core.communication.NodeKey;
import network.thunder.core.helper.callback.Command;

public class ConnectionProcessor extends AuthenticatedProcessor implements Connection {
Expand All @@ -21,7 +20,7 @@ public ConnectionProcessor (ContextFactory contextFactory, ClientObject clientOb
@Override
public void onLayerActive (MessageExecutor messageExecutor) {
messageExecutor.sendNextLayerActive();
setNode(new NodeKey(node.pubKeyClient));
setNode(node.nodeKey);
this.messageExecutor = messageExecutor;
connectionRegistry.onConnected(getNode(), this);
node.onConnectionComplete.stream().forEach(Command::execute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import network.thunder.core.communication.layer.high.channel.establish.LNEstablishProcessor;
import network.thunder.core.communication.layer.high.channel.establish.messages.LNEstablishMessageFactory;
import network.thunder.core.communication.layer.high.payments.*;
import network.thunder.core.communication.layer.high.payments.messages.LNPaymentMessageFactory;
import network.thunder.core.communication.layer.low.ack.AckProcessor;
import network.thunder.core.communication.layer.low.authentication.AuthenticationProcessor;
import network.thunder.core.communication.layer.low.authentication.messages.AuthenticationMessageFactory;
import network.thunder.core.communication.layer.low.encryption.EncryptionProcessor;
Expand Down Expand Up @@ -45,6 +45,8 @@ public interface ContextFactory {

GossipProcessor getGossipProcessor (ClientObject node);

AckProcessor getAckProcessor (ClientObject node);

LNEstablishProcessor getLNEstablishProcessor (ClientObject node);

LNPaymentProcessor getLNPaymentProcessor (ClientObject node);
Expand Down Expand Up @@ -81,8 +83,6 @@ public interface ContextFactory {

LNEstablishMessageFactory getLNEstablishMessageFactory ();

LNPaymentMessageFactory getLNPaymentMessageFactory ();

LNCloseMessageFactory getLNCloseMessageFactory ();

LNCloseProcessor getLNCloseProcessor (ClientObject node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
import network.thunder.core.communication.layer.high.channel.establish.messages.LNEstablishMessageFactory;
import network.thunder.core.communication.layer.high.channel.establish.messages.LNEstablishMessageFactoryImpl;
import network.thunder.core.communication.layer.high.payments.*;
import network.thunder.core.communication.layer.high.payments.messages.LNPaymentMessageFactory;
import network.thunder.core.communication.layer.high.payments.messages.LNPaymentMessageFactoryImpl;

import network.thunder.core.communication.layer.low.ack.AckProcessor;
import network.thunder.core.communication.layer.low.ack.AckProcessorImpl;
import network.thunder.core.communication.layer.low.authentication.AuthenticationProcessor;
import network.thunder.core.communication.layer.low.authentication.AuthenticationProcessorImpl;
import network.thunder.core.communication.layer.low.authentication.messages.AuthenticationMessageFactory;
Expand Down Expand Up @@ -57,6 +58,7 @@ public class ContextFactoryImpl implements ContextFactory {
WalletHelper walletHelper;

LNPaymentHelper paymentHelper;
LNPaymentLogic paymentLogic;

LNOnionHelper onionHelper = new LNOnionHelperImpl();

Expand All @@ -74,6 +76,7 @@ public ContextFactoryImpl (ServerObject node, DBHandler dbHandler, Wallet wallet
this.eventHelper = eventHelper;
this.walletHelper = new WalletHelperImpl(wallet);

this.paymentLogic = new LNPaymentLogicImpl();
GossipSubjectImpl gossipSubject = new GossipSubjectImpl(dbHandler, eventHelper);
this.gossipSubject = gossipSubject;
this.broadcastHelper = gossipSubject;
Expand All @@ -82,7 +85,7 @@ public ContextFactoryImpl (ServerObject node, DBHandler dbHandler, Wallet wallet

this.paymentHelper = new LNPaymentHelperImpl(this, dbHandler);

if(Constants.USE_MOCK_BLOCKCHAIN) {
if (Constants.USE_MOCK_BLOCKCHAIN) {
this.blockchainHelper = new MockBlockchainHelper(wallet);
} else {
this.blockchainHelper = new BlockchainHelperImpl(wallet);
Expand Down Expand Up @@ -130,6 +133,11 @@ public GossipProcessor getGossipProcessor (ClientObject node) {
return new GossipProcessorImpl(this, dbHandler, node);
}

@Override
public AckProcessor getAckProcessor (ClientObject node) {
return new AckProcessorImpl(this, dbHandler, node);
}

@Override
public LNEstablishProcessor getLNEstablishProcessor (ClientObject node) {
return new LNEstablishProcessorImpl(this, dbHandler, node);
Expand Down Expand Up @@ -182,7 +190,7 @@ public GossipSubject getGossipSubject () {

@Override
public LNPaymentLogic getLNPaymentLogic () {
return new LNPaymentLogicImpl(getLNPaymentMessageFactory(), dbHandler);
return paymentLogic;
}

@Override
Expand Down Expand Up @@ -220,11 +228,6 @@ public LNEstablishMessageFactory getLNEstablishMessageFactory () {
return new LNEstablishMessageFactoryImpl();
}

@Override
public LNPaymentMessageFactory getLNPaymentMessageFactory () {
return new LNPaymentMessageFactoryImpl(dbHandler);
}

@Override
public LNCloseMessageFactory getLNCloseMessageFactory () {
return new LNCloseMessageFactoryImpl();
Expand Down
Loading

0 comments on commit 2494191

Please sign in to comment.