Skip to content
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

fix: some portal-hive test err #31

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions p2p/discover/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/holiman/uint256"
)

// json-rpc spec
// https://playground.open-rpc.org/?schemaUrl=https://raw.githubusercontent.com/ethereum/portal-network-specs/assembled-spec/jsonrpc/openrpc.json&uiSchema%5BappBar%5D%5Bui:splitView%5D=false&uiSchema%5BappBar%5D%5Bui:input%5D=false&uiSchema%5BappBar%5D%5Bui:examplesDropdown%5D=false
type DiscV5API struct {
DiscV5 *UDPv5
}
Expand Down Expand Up @@ -214,7 +216,7 @@ func (p *PortalAPI) NodeInfo() *NodeInfo {
}
}

func (p *PortalAPI) RoutingTableInfo() *RoutingTableInfo {
func (p *PortalAPI) HistoryRoutingTableInfo() *RoutingTableInfo {
n := p.portalProtocol.localNode.Node()

closestNodes := p.portalProtocol.table.Nodes()
Expand Down Expand Up @@ -279,7 +281,7 @@ func (p *PortalAPI) HistoryDeleteEnr(nodeId string) (bool, error) {

n := p.portalProtocol.table.getNode(id)
if n == nil {
return false, errors.New("record not in local routing table")
return false, nil
}

p.portalProtocol.table.delete(wrapNode(n))
Expand All @@ -301,7 +303,7 @@ func (p *PortalAPI) HistoryLookupEnr(nodeId string) (string, error) {
return enr.String(), nil
}

func (p *PortalAPI) Ping(enr string) (*PortalPongResp, error) {
func (p *PortalAPI) HistoryPing(enr string) (*PortalPongResp, error) {
n, err := enode.Parse(enode.ValidSchemes, enr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -330,7 +332,7 @@ func (p *PortalAPI) Ping(enr string) (*PortalPongResp, error) {
}, nil
}

func (p *PortalAPI) FindNodes(enr string, distances []uint) ([]string, error) {
func (p *PortalAPI) HistoryFindNodes(enr string, distances []uint) ([]string, error) {
n, err := enode.Parse(enode.ValidSchemes, enr)
if err != nil {
return nil, err
Expand All @@ -348,7 +350,7 @@ func (p *PortalAPI) FindNodes(enr string, distances []uint) ([]string, error) {
return enrs, nil
}

func (p *PortalAPI) FindContent(enr string, contentKey string) (interface{}, error) {
func (p *PortalAPI) HistoryFindContent(enr string, contentKey string) (interface{}, error) {
n, err := enode.Parse(enode.ValidSchemes, enr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -387,7 +389,7 @@ func (p *PortalAPI) FindContent(enr string, contentKey string) (interface{}, err
}
}

func (p *PortalAPI) Offer(enr string, contentKey string, contentValue string) (string, error) {
func (p *PortalAPI) HistoryOffer(enr string, contentKey string, contentValue string) (string, error) {
n, err := enode.Parse(enode.ValidSchemes, enr)
if err != nil {
return "", err
Expand Down Expand Up @@ -440,6 +442,12 @@ func (p *PortalAPI) HistoryRecursiveFindContent(contentKeyHex string) (*ContentI
return nil, err
}
content, utpTransfer, err := p.portalProtocol.ContentLookup(contentKey)
if errors.Is(err, storage.ErrContentNotFound) {
return &ContentInfo{
Content: "0x",
UtpTransfer: false,
}, nil
}
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -485,3 +493,13 @@ func (p *PortalAPI) HistoryStore(contentKeyHex string, contextHex string) (bool,
}
return true, nil
}

// TODO
func (p *PortalAPI) HistoryGossip() {

}

// TODO
func (p *PortalAPI) HistoryTraceRecursiveFindContent(contentKeyHex string) {

}