Small cleanup
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
2b906efa1e
commit
adcd87abb0
@ -19,12 +19,7 @@ func WriteCborRPC(w io.Writer, obj interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
type ByteReader interface {
|
func ReadCborRPC(r io.Reader, out interface{}) error {
|
||||||
io.Reader
|
|
||||||
io.ByteReader
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadCborRPC(r ByteReader, out interface{}) error {
|
|
||||||
b, err := ioutil.ReadAll(r)
|
b, err := ioutil.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
1
go.sum
1
go.sum
@ -82,6 +82,7 @@ github.com/ipfs/go-ipfs-routing v0.1.0 h1:gAJTT1cEeeLj6/DlLX6t+NxD9fQe2ymTO6qWRD
|
|||||||
github.com/ipfs/go-ipfs-routing v0.1.0/go.mod h1:hYoUkJLyAUKhF58tysKpids8RNDPO42BVMgK5dNsoqY=
|
github.com/ipfs/go-ipfs-routing v0.1.0/go.mod h1:hYoUkJLyAUKhF58tysKpids8RNDPO42BVMgK5dNsoqY=
|
||||||
github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv50=
|
github.com/ipfs/go-ipfs-util v0.0.1 h1:Wz9bL2wB2YBJqggkA4dD7oSmqB4cAnpNbGrlHJulv50=
|
||||||
github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc=
|
github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc=
|
||||||
|
github.com/ipfs/go-ipld-cbor v0.0.2 h1:amzFztBQQQ69UA5+f7JRfoXF/z2l//MGfEDHVkS20+s=
|
||||||
github.com/ipfs/go-ipld-cbor v0.0.2/go.mod h1:wTBtrQZA3SoFKMVkp6cn6HMRteIB1VsmHA0AQFOn7Nc=
|
github.com/ipfs/go-ipld-cbor v0.0.2/go.mod h1:wTBtrQZA3SoFKMVkp6cn6HMRteIB1VsmHA0AQFOn7Nc=
|
||||||
github.com/ipfs/go-ipld-format v0.0.1 h1:HCu4eB/Gh+KD/Q0M8u888RFkorTWNIL3da4oc5dwc80=
|
github.com/ipfs/go-ipld-format v0.0.1 h1:HCu4eB/Gh+KD/Q0M8u888RFkorTWNIL3da4oc5dwc80=
|
||||||
github.com/ipfs/go-ipld-format v0.0.1/go.mod h1:kyJtbkDALmFHv3QR6et67i35QzO3S0dCDnkOJhcZkms=
|
github.com/ipfs/go-ipld-format v0.0.1/go.mod h1:kyJtbkDALmFHv3QR6et67i35QzO3S0dCDnkOJhcZkms=
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package hello
|
package hello
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-lotus/cborrpc"
|
"github.com/filecoin-project/go-lotus/cborrpc"
|
||||||
"github.com/libp2p/go-libp2p-core/host"
|
"github.com/libp2p/go-libp2p-core/host"
|
||||||
|
|
||||||
@ -46,15 +46,15 @@ func NewHelloService(h host.Host) *Service {
|
|||||||
func (hs *Service) HandleStream(s inet.Stream) {
|
func (hs *Service) HandleStream(s inet.Stream) {
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
log.Debugw("Handling hello")
|
|
||||||
|
|
||||||
var hmsg Message
|
var hmsg Message
|
||||||
if err := cborrpc.ReadCborRPC(bufio.NewReader(s), &hmsg); err != nil {
|
if err := cborrpc.ReadCborRPC(s, &hmsg); err != nil {
|
||||||
log.Error("failed to read hello message: ", err)
|
log.Infow("failed to read hello message", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Debugw("heaviest tipset", "tipset", hmsg.HeaviestTipSet)
|
log.Debugw("genesis from hello",
|
||||||
log.Debugw("got genesis from hello", "hash", hmsg.GenesisHash)
|
"tipset", hmsg.HeaviestTipSet,
|
||||||
|
"peer", s.Conn().RemotePeer(),
|
||||||
|
"hash", hmsg.GenesisHash)
|
||||||
|
|
||||||
/*if hmsg.GenesisHash != hs.syncer.genesis.Cids()[0] {
|
/*if hmsg.GenesisHash != hs.syncer.genesis.Cids()[0] {
|
||||||
log.Error("other peer has different genesis!")
|
log.Error("other peer has different genesis!")
|
||||||
|
Loading…
Reference in New Issue
Block a user