Skip to content

Commit

Permalink
Merge pull request #45 from vulcanize/fix
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
i-norden authored Apr 11, 2021
2 parents 677cdf0 + aff66d9 commit f4ff261
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions pkg/net/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,24 @@ func NewPublicNetAPI(networkID uint64, client *rpc.Client) *PublicNetAPI {

// Listening returns an indication if the node is listening for network connections.
func (pna *PublicNetAPI) Listening() bool {
return false // currently our nodes are never listening on the p2p network
// in this case it is actually whether or not the proxied node is listening
if pna.rpc != nil {
var listening bool
if err := pna.rpc.Call(&listening, "net_listening"); err == nil {
return listening
}
}
return false
}

// PeerCount returns the number of connected peers
func (pna *PublicNetAPI) PeerCount() hexutil.Uint {
num := new(hexutil.Uint)
// in this case it is actually the peercount of the proxied node
if err := pna.rpc.Call(num, "net_peerCount"); num != nil && err == nil {
return *num
// in this case it is actually the peer count of the proxied node
if pna.rpc != nil {
var num hexutil.Uint
if err := pna.rpc.Call(&num, "net_peerCount"); err == nil {
return num
}
}
return hexutil.Uint(0)
}
Expand All @@ -71,9 +80,11 @@ func (pna *PublicNetAPI) Version() string {
if pna.networkVersion != 0 {
return fmt.Sprintf("%d", pna.networkVersion)
}
version := new(string)
if err := pna.rpc.Call(version, "net_version"); version != nil && err == nil {
return *version
if pna.rpc != nil {
var version string
if err := pna.rpc.Call(&version, "net_version"); err == nil {
return version
}
}
return ""
}
2 changes: 1 addition & 1 deletion pkg/net/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ var _ = Describe("API", func() {
Expect(version).To(Equal("1"))
})
})
// TODO: test PeerCount and proxying
// TODO: test PeerCount with mock proxy node
})

0 comments on commit f4ff261

Please sign in to comment.