github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/qln/eventhandlers.go (about) 1 package qln 2 3 import ( 4 "github.com/mit-dci/lit/eventbus" 5 "github.com/mit-dci/lit/lnp2p" 6 "github.com/mit-dci/lit/lnutil" 7 "github.com/mit-dci/lit/logging" 8 ) 9 10 func makeTmpNewPeerHandler(nd *LitNode) func(eventbus.Event) eventbus.EventHandleResult { 11 return func(e eventbus.Event) eventbus.EventHandleResult { 12 13 ee := e.(lnp2p.NewPeerEvent) 14 15 peerIdx := uint32(nd.PeerMan.GetPeerIdx(ee.Peer)) 16 17 logging.Debugf("creating new fake RemotePeer %d\n", peerIdx) 18 19 rpeer := &RemotePeer{ 20 Idx: peerIdx, 21 Con: ee.Conn, 22 Nickname: ee.Peer.GetNickname(), 23 QCs: make(map[uint32]*Qchan), 24 } 25 26 nd.PeerMapMtx.Lock() 27 nd.RemoteMtx.Lock() 28 29 nd.RemoteCons[peerIdx] = rpeer 30 nd.PeerMap[ee.Peer] = rpeer 31 32 nd.RemoteMtx.Unlock() 33 nd.PeerMapMtx.Unlock() 34 35 // populate things 36 nd.PopulateQchanMap(rpeer) 37 38 // make a local map of outpoints to channel indexes 39 // iterate through all this peer's channels to extract outpoints 40 rpeer.OpMap = make(map[[36]byte]uint32) 41 for _, q := range rpeer.QCs { 42 opArr := lnutil.OutPointToBytes(q.Op) 43 rpeer.OpMap[opArr] = q.Idx() 44 } 45 46 return eventbus.EHANDLE_OK 47 } 48 } 49 50 func makeTmpDisconnectPeerHandler(nd *LitNode) func(eventbus.Event) eventbus.EventHandleResult { 51 return func(e eventbus.Event) eventbus.EventHandleResult { 52 ee := e.(lnp2p.PeerDisconnectEvent) 53 rpeer := nd.PeerMap[ee.Peer] 54 55 nd.RemoteMtx.Lock() 56 delete(nd.RemoteCons, rpeer.Idx) 57 delete(nd.PeerMap, ee.Peer) 58 nd.RemoteMtx.Unlock() 59 60 return eventbus.EHANDLE_OK 61 } 62 } 63 64 func makeTmpSigProofHandler(nd *LitNode) func(eventbus.Event) eventbus.EventHandleResult { 65 return func(e eventbus.Event) eventbus.EventHandleResult { 66 ee, ok := e.(ChannelStateUpdateEvent) 67 if !ok { 68 logging.Errorf("Wrong type of event, why are you publishing this") 69 // I think this is the right way to cancel the event? 70 return eventbus.EHANDLE_CANCEL 71 } 72 73 logging.Infof("Sig proof!") 74 75 logging.Infof("Channel succeeded: %t, MyAmt: %d", !ee.State.Failed, ee.State.MyAmt) 76 77 logging.Infof("got a fund event: %d", ee.ChanIdx) 78 return eventbus.EHANDLE_OK 79 } 80 }