daemon: implement send and receive
Currently we have this problem 2024-03-26T22:35:58.902Z DEBUG hsmd: Client: Received message 1 from client 2024-03-26T22:35:58.903Z DEBUG 0387d3a40b5eca0058753afa0ed3ee1b3e34ea5203a72f3b42b35b24d4eae421e5-connectd: Connect IN 2024-03-26T22:35:58.903Z 0387d3a40b5eca0058753afa0ed3ee1b3e34ea5203a72f3b42b35b24d4eae421e5-connectd: [OUT] 001000021100000708a0000a8a5961012006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f0307017f000001e9b4 2024-03-26T22:35:58.905Z 0387d3a40b5eca0058753afa0ed3ee1b3e34ea5203a72f3b42b35b24d4eae421e5-connectd: [IN] 001000021100000708a0000a8a5961 2024-03-26T22:35:58.905Z DEBUG 0387d3a40b5eca0058753afa0ed3ee1b3e34ea5203a72f3b42b35b24d4eae421e5-lightningd: peer_disconnect_done 2024-03-26T22:35:58.905Z DEBUG 0387d3a40b5eca0058753afa0ed3ee1b3e34ea5203a72f3b42b35b24d4eae421e5-lightningd: Not reconnecting: no active channel Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
parent
935a1e0775
commit
751d3600ce
4
go.mod
4
go.mod
|
@ -4,13 +4,14 @@ go 1.22
|
|||
|
||||
require (
|
||||
github.com/akamensky/argparse v1.4.0
|
||||
github.com/btcsuite/btcd v0.23.1
|
||||
github.com/btcsuite/btcd/btcec/v2 v2.2.0
|
||||
github.com/lightningnetwork/lnd v0.15.0-beta
|
||||
github.com/sourcegraph/jsonrpc2 v0.2.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/aead/siphash v1.0.1 // indirect
|
||||
github.com/btcsuite/btcd v0.23.1 // indirect
|
||||
github.com/btcsuite/btcd/btcutil v1.1.1 // indirect
|
||||
github.com/btcsuite/btcd/btcutil/psbt v1.1.4 // indirect
|
||||
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
|
||||
|
@ -37,7 +38,6 @@ require (
|
|||
github.com/lightningnetwork/lnd/tlv v1.0.3 // indirect
|
||||
github.com/lightningnetwork/lnd/tor v1.0.1 // indirect
|
||||
github.com/miekg/dns v1.1.43 // indirect
|
||||
github.com/sourcegraph/jsonrpc2 v0.2.0 // indirect
|
||||
github.com/stretchr/testify v1.8.4 // indirect
|
||||
golang.org/x/crypto v0.21.0 // indirect
|
||||
golang.org/x/net v0.21.0 // indirect
|
||||
|
|
|
@ -50,16 +50,15 @@ func Make() (*ProtoTestServer, error) {
|
|||
// / Connect - Perform the connection with the peer with
|
||||
// / the provided public key (aka nodeId) that it is listening
|
||||
// / on the specified port.
|
||||
func (self *ProtoTestServer) Connect(nodeId string, port uint32, network wire.BitcoinNet) error {
|
||||
func (self *ProtoTestServer) Connect(nodeId string, port uint32, network wire.BitcoinNet) (*bytes.Buffer, error) {
|
||||
pubkey, err := StringToPubKey(nodeId)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
hostname := fmt.Sprintf("127.0.0.1:%d", port)
|
||||
fmt.Printf("\n*******%s******\n", hostname)
|
||||
addr, err := net.ResolveTCPAddr("tcp", hostname)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
wireaddr := lnwire.NetAddress{
|
||||
Address: addr,
|
||||
|
@ -68,21 +67,35 @@ func (self *ProtoTestServer) Connect(nodeId string, port uint32, network wire.Bi
|
|||
}
|
||||
conn, err := brontide.Dial(&self.PrivKeyECDH, &wireaddr, time.Second*3, net.DialTimeout)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
self.Conn = conn
|
||||
return nil
|
||||
if err := self.Conn.SetDeadline(time.Now().Add(time.Second)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return self.Receive()
|
||||
}
|
||||
|
||||
// / Send - Send an message to the connection
|
||||
func (self *ProtoTestServer) Send(buff *bytes.Buffer) error {
|
||||
size, err := self.Conn.Write(buff.Bytes())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if size == 0 {
|
||||
return fmt.Errorf("No message to flush")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// / Send - Wait a message from the connection, usually this is
|
||||
// / an answer from a previous send message
|
||||
func (self *ProtoTestServer) Receive() (*bytes.Buffer, error) {
|
||||
return nil, nil
|
||||
buff, err := self.Conn.ReadNextMessage()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bytes.NewBuffer(buff), nil
|
||||
}
|
||||
|
||||
// / Destroy - Stop the connecto for lnprototest
|
||||
|
|
|
@ -14,6 +14,9 @@ import (
|
|||
type ConnectRPC struct {
|
||||
NodeId string
|
||||
Port uint32
|
||||
// Afeter the connection we should have a
|
||||
// init message from the node
|
||||
Msg string
|
||||
}
|
||||
|
||||
func ConnectCall(request *json.RawMessage, response *json.RawMessage) error {
|
||||
|
@ -22,10 +25,15 @@ func ConnectCall(request *json.RawMessage, response *json.RawMessage) error {
|
|||
if err := json.Unmarshal(*request, &connect); err != nil {
|
||||
return nil
|
||||
}
|
||||
if err := lnprototestServer.Connect(connect.NodeId, connect.Port, wire.SimNet); err != nil {
|
||||
resp, err := lnprototestServer.Connect(connect.NodeId, connect.Port, wire.SimNet)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
connect.Msg = hex.EncodeToString(resp.Bytes())
|
||||
*response, err = json.Marshal(connect)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*response = *request
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue