From 5ebaf9d1e7caa743c6ec0c6b01886cba0b96b0a9 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 20 Sep 2016 16:07:22 -0700 Subject: [PATCH] routing: vertexes are now serialized pub keys instead of pubkey hashes --- fundingmanager.go | 8 +++++--- rpcserver.go | 2 +- server.go | 20 +++++++++++++------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index fe5069f9..8b7ea7c8 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -583,9 +583,10 @@ func (f *fundingManager) handleFundingSignComplete(fmsg *fundingSignCompleteMsg) // so this new channel can be utilized during path // finding. chanInfo := openChan.StateSnapshot() - capacity := int64(chanInfo.Capacity) + capacity := int64(chanInfo.LocalBalance + chanInfo.RemoteBalance) + vertex := hex.EncodeToString(fmsg.peer.identityPub.SerializeCompressed()) fmsg.peer.server.routingMgr.OpenChannel( - graph.NewID(chanInfo.RemoteID), + graph.NewID(vertex), graph.NewEdgeID(fundingPoint.String()), &rt.ChannelInfo{ Cpt: capacity, @@ -655,8 +656,9 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) { // Notify the L3 routing manager of the newly active channel link. capacity := int64(resCtx.reservation.OurContribution().FundingAmount + resCtx.reservation.TheirContribution().FundingAmount) + vertex := hex.EncodeToString(fmsg.peer.identityPub.SerializeCompressed()) fmsg.peer.server.routingMgr.OpenChannel( - graph.NewID([32]byte(fmsg.peer.lightningID)), + graph.NewID(vertex), graph.NewEdgeID(resCtx.reservation.FundingOutpoint().String()), &rt.ChannelInfo{ Cpt: capacity, diff --git a/rpcserver.go b/rpcserver.go index 6feaa6fa..38e3ef2a 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -208,7 +208,7 @@ out: select { case err := <-errChan: rpcsLog.Errorf("unable to open channel to "+ - "lightningID(%v) nor peerID(%v): %v", + "lightningID(%x) nor peerID(%v): %v", in.TargetNode, in.TargetPeerId, err) return err case fundingUpdate := <-updateChan: diff --git a/server.go b/server.go index af289a43..91f866ca 100644 --- a/server.go +++ b/server.go @@ -118,7 +118,8 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier, // Create a new routing manager with ourself as the sole node within // the graph. - s.routingMgr = routing.NewRoutingManager(graph.NewID(s.lightningID), nil) + selfVertex := hex.EncodeToString(serializedPubKey) + s.routingMgr = routing.NewRoutingManager(graph.NewID(selfVertex), nil) s.rpcServer = newRpcServer(s) @@ -306,22 +307,27 @@ out: msg1 := msg.(*routing.RoutingMessage) if msg1.ReceiverID == nil { peerLog.Critical("msg1.GetReceiverID() == nil") + continue } - receiverID := msg1.ReceiverID.ToByte32() + receiverID := msg1.ReceiverID.String() + var targetPeer *peer for _, peer := range s.peers { // TODO: threadsafe api + nodePub := peer.identityPub.SerializeCompressed() + idStr := hex.EncodeToString(nodePub) + // We found the the target - if peer.lightningID == receiverID { + if receiverID == idStr { targetPeer = peer break } } + if targetPeer != nil { - fndgLog.Info("Peer found. Sending message") - done := make(chan struct{}, 1) - targetPeer.queueMsg(msg1.Msg, done) + targetPeer.queueMsg(msg1.Msg, nil) } else { - srvrLog.Errorf("Can't find peer to send message %v", receiverID) + srvrLog.Errorf("Can't find peer to send message %v", + receiverID) } case <-s.quit: break out