-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add bitcoin support to nebula #84
base: main
Are you sure you want to change the base?
Conversation
type AddrInfo struct { | ||
id string | ||
Addr []ma.Multiaddr | ||
} | ||
type PeerInfo struct { | ||
AddrInfo | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move the fields into the PeerInfo
struct. I don't think the nesting is necessary. You can also export the id
field like so:
type AddrInfo struct { | |
id string | |
Addr []ma.Multiaddr | |
} | |
type PeerInfo struct { | |
AddrInfo | |
} | |
type PeerInfo struct { | |
ID string | |
Addr []ma.Multiaddr | |
} |
bitcoin/driver_crawler.go
Outdated
type CrawlDriverConfig struct { | ||
Version string | ||
TrackNeighbors bool | ||
DialTimeout time.Duration | ||
BootstrapPeers []ma.Multiaddr | ||
AddrDialType config.AddrType | ||
AddrTrackType config.AddrType | ||
KeepENR bool | ||
MeterProvider metric.MeterProvider | ||
TracerProvider trace.TracerProvider | ||
LogErrors bool | ||
UDPBufferSize int | ||
UDPRespTimeout time.Duration | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the following fields.
type CrawlDriverConfig struct { | |
Version string | |
TrackNeighbors bool | |
DialTimeout time.Duration | |
BootstrapPeers []ma.Multiaddr | |
AddrDialType config.AddrType | |
AddrTrackType config.AddrType | |
KeepENR bool | |
MeterProvider metric.MeterProvider | |
TracerProvider trace.TracerProvider | |
LogErrors bool | |
UDPBufferSize int | |
UDPRespTimeout time.Duration | |
} | |
type CrawlDriverConfig struct { | |
Version string | |
TrackNeighbors bool | |
DialTimeout time.Duration | |
BootstrapPeers []ma.Multiaddr | |
MeterProvider metric.MeterProvider | |
TracerProvider trace.TracerProvider | |
LogErrors bool | |
} |
maybe Version
can also be removed.
"dnsseed.bitcoin.dashjr.org", | ||
"seed.bitcoinstats.com", | ||
"seed.bitnodes.io", | ||
"bitseed.xf2.org", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using multi address format:
"bitseed.xf2.org", | |
"/dns/bitseed.xf2.org", |
Could you also add the new network to the readme and perhaps mark it as alpha? |
// there is no other reliable transport address like TCP or QUIC we use the UDP | ||
// IP address + port and craft a TCP address out of it. The UDP address will | ||
// still be removed and replaced with TCP. | ||
func sanitizeAddrs(maddrs []ma.Multiaddr) ([]ma.Multiaddr, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is obsolete and can be removed
if conn == nil { | ||
log.Infoln("SOMETHING IS WRONG!!!!") | ||
} | ||
return wire.WriteMessage(conn, msg, wire.ProtocolVersion, wire.MainNet) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if conn == nil { | |
log.Infoln("SOMETHING IS WRONG!!!!") | |
} | |
return wire.WriteMessage(conn, msg, wire.ProtocolVersion, wire.MainNet) | |
return wire.WriteMessage(conn, msg, wire.ProtocolVersion, wire.MainNet) |
}) | ||
logEntry.Debugln("Connecting to peer", pi.ID.ShortString()) | ||
|
||
netAddr, _ := manet.ToNetAddr(pi.Addrs[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handle error
// addrInfo := peer.AddrInfo{ | ||
// ID: pi.ID(), | ||
// Addrs: sanitizedAddrs, | ||
// } | ||
|
||
var conn net.Conn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// addrInfo := peer.AddrInfo{ | |
// ID: pi.ID(), | |
// Addrs: sanitizedAddrs, | |
// } | |
var conn net.Conn | |
var conn net.Conn |
} | ||
result.Error = err | ||
resultCh <- result | ||
close(resultCh) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather do a defer close(resultCh)
and also remove the close
call at the end of the function
close(resultCh) | ||
return | ||
} | ||
// conn, result.ConnectError = c.connect(ctx, addrInfo) // use filtered addr list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, why the connect method below and this here? I would prefer to keep and use a dedicated connect
method that abstracts away the error case handling and only returns an error if we really couldn't connect on any of the provided addresses.
result.Agent = nodeRes.UserAgent | ||
result.ProtocolVersion = nodeRes.ProtocolVersion | ||
if err != nil { | ||
log.Debugf("[%s] Handshake failed: %v", addrs, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather use the WithError
method on the logger. Also the log messages below.
firstReceived := -1 | ||
tolerateMessages := 5 | ||
// The nodes send a lot of inv messages | ||
tolerateInvMessages := 50 | ||
tolerateVerAckMessages := 10 | ||
toleratePingMessages := 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you in a brief code comment explain the logic behind the message "toleration"
if conn != nil { | ||
if err := conn.Close(); err != nil { | ||
log.WithError(err).WithField("remoteID", pi.ID().ShortString()).Warnln("Could not close connection on context cancel") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather put this in a defer
statement at the point in the code where you have received the connection object.
Addr: []ma.Multiaddr{maddr}, | ||
}, | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any chance to remove the code duplication with above?
This PR introduces Bitcoin network support to the Nebula crawler by implementing necessary interfaces, integrating the
btcsuite/btcd/wire
package, and adding a basic Bitcoin network crawler. Key changes include:1. Interface Implementations
PeerInfo
:CrawlDriverConfig
:CrawlDriver
:2. Bitcoin Network Integration
--network bitcoin
).CrawlDriver
.3. Error Handling and Protocol Compliance
4.
btcsuite/btcd/wire
Package Integrationbtcsuite/btcd/wire
for Bitcoin protocol implementation.5. Basic Bitcoin Network Crawler Implementation