fix #45

Merged
telackey merged 1 commits from fix into master 2021-04-11 02:29:33 +00:00
2 changed files with 20 additions and 9 deletions

View File

@ -53,15 +53,24 @@ func NewPublicNetAPI(networkID uint64, client *rpc.Client) *PublicNetAPI {
// Listening returns an indication if the node is listening for network connections. // Listening returns an indication if the node is listening for network connections.
func (pna *PublicNetAPI) Listening() bool { 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 // PeerCount returns the number of connected peers
func (pna *PublicNetAPI) PeerCount() hexutil.Uint { func (pna *PublicNetAPI) PeerCount() hexutil.Uint {
num := new(hexutil.Uint) // in this case it is actually the peer count of the proxied node
// in this case it is actually the peercount of the proxied node if pna.rpc != nil {
if err := pna.rpc.Call(num, "net_peerCount"); num != nil && err == nil { var num hexutil.Uint
return *num if err := pna.rpc.Call(&num, "net_peerCount"); err == nil {
return num
}
} }
return hexutil.Uint(0) return hexutil.Uint(0)
} }
@ -71,9 +80,11 @@ func (pna *PublicNetAPI) Version() string {
if pna.networkVersion != 0 { if pna.networkVersion != 0 {
return fmt.Sprintf("%d", pna.networkVersion) return fmt.Sprintf("%d", pna.networkVersion)
} }
version := new(string) if pna.rpc != nil {
if err := pna.rpc.Call(version, "net_version"); version != nil && err == nil { var version string
return *version if err := pna.rpc.Call(&version, "net_version"); err == nil {
return version
}
} }
return "" return ""
} }

View File

@ -43,5 +43,5 @@ var _ = Describe("API", func() {
Expect(version).To(Equal("1")) Expect(version).To(Equal("1"))
}) })
}) })
// TODO: test PeerCount and proxying // TODO: test PeerCount with mock proxy node
}) })