From f4ddb9ddcb0cd402654f0b5b2e6723840c8c9b62 Mon Sep 17 00:00:00 2001 From: fearlessfe <505380967@qq.com> Date: Wed, 9 Oct 2024 23:45:14 +0800 Subject: [PATCH 1/2] feat: offer json rpc change --- p2p/discover/api.go | 31 +++++++++++++++++-------------- portalnetwork/beacon/api.go | 4 ++-- portalnetwork/history/api.go | 4 ++-- portalnetwork/state/api.go | 4 ++-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/p2p/discover/api.go b/p2p/discover/api.go index ed306f312f88..07a5b61dc432 100644 --- a/p2p/discover/api.go +++ b/p2p/discover/api.go @@ -415,28 +415,31 @@ func (p *PortalProtocolAPI) FindContent(enr string, contentKey string) (interfac } } -func (p *PortalProtocolAPI) Offer(enr string, contentKey string, contentValue string) (string, error) { +func (p *PortalProtocolAPI) Offer(enr string, contentItems [][2]string) (string, error) { n, err := enode.Parse(enode.ValidSchemes, enr) if err != nil { return "", err } - contentKeyBytes, err := hexutil.Decode(contentKey) - if err != nil { - return "", err - } - contentValueBytes, err := hexutil.Decode(contentValue) - if err != nil { - return "", err - } - - contentEntry := &ContentEntry{ - ContentKey: contentKeyBytes, - Content: contentValueBytes, + entries := make([]*ContentEntry, 0, len(contentItems)); + for _, contentItem := range contentItems { + contentKey, err := hexutil.Decode(contentItem[0]) + if err != nil { + return "", err + } + contentValue, err := hexutil.Decode(contentItem[1]) + if err != nil { + return "", err + } + contentEntry := &ContentEntry{ + ContentKey: contentKey, + Content: contentValue, + } + entries = append(entries, contentEntry) } transientOfferRequest := &TransientOfferRequest{ - Contents: []*ContentEntry{contentEntry}, + Contents: entries, } offerReq := &OfferRequest{ diff --git a/portalnetwork/beacon/api.go b/portalnetwork/beacon/api.go index f9358c56c72d..a74455759df0 100644 --- a/portalnetwork/beacon/api.go +++ b/portalnetwork/beacon/api.go @@ -40,8 +40,8 @@ func (p *API) BeaconFindContent(enr string, contentKey string) (interface{}, err return p.FindContent(enr, contentKey) } -func (p *API) BeaconOffer(enr string, contentKey string, contentValue string) (string, error) { - return p.Offer(enr, contentKey, contentValue) +func (p *API) BeaconOffer(enr string, contentItems [][2]string) (string, error) { + return p.Offer(enr, contentItems) } func (p *API) BeaconRecursiveFindNodes(nodeId string) ([]string, error) { diff --git a/portalnetwork/history/api.go b/portalnetwork/history/api.go index 926bca7cf9bc..62245eed1523 100644 --- a/portalnetwork/history/api.go +++ b/portalnetwork/history/api.go @@ -40,8 +40,8 @@ func (p *API) HistoryFindContent(enr string, contentKey string) (interface{}, er return p.FindContent(enr, contentKey) } -func (p *API) HistoryOffer(enr string, contentKey string, contentValue string) (string, error) { - return p.Offer(enr, contentKey, contentValue) +func (p *API) HistoryOffer(enr string, contentItems [][2]string) (string, error) { + return p.Offer(enr, contentItems) } func (p *API) HistoryRecursiveFindNodes(nodeId string) ([]string, error) { diff --git a/portalnetwork/state/api.go b/portalnetwork/state/api.go index a09f88d595a8..875e1ab24880 100644 --- a/portalnetwork/state/api.go +++ b/portalnetwork/state/api.go @@ -40,8 +40,8 @@ func (p *API) StateFindContent(enr string, contentKey string) (interface{}, erro return p.FindContent(enr, contentKey) } -func (p *API) StateOffer(enr string, contentKey string, contentValue string) (string, error) { - return p.Offer(enr, contentKey, contentValue) +func (p *API) StateOffer(enr string, contentItems [][2]string) (string, error) { + return p.Offer(enr, contentItems) } func (p *API) StateRecursiveFindNodes(nodeId string) ([]string, error) { From 7cf3e699cf706d7bc293f94240e23afd857f018b Mon Sep 17 00:00:00 2001 From: fearlseefe <505380967@qq.com> Date: Thu, 10 Oct 2024 10:35:52 +0800 Subject: [PATCH 2/2] fix: lint err --- p2p/discover/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/discover/api.go b/p2p/discover/api.go index 07a5b61dc432..4915fa688e2a 100644 --- a/p2p/discover/api.go +++ b/p2p/discover/api.go @@ -421,7 +421,7 @@ func (p *PortalProtocolAPI) Offer(enr string, contentItems [][2]string) (string, return "", err } - entries := make([]*ContentEntry, 0, len(contentItems)); + entries := make([]*ContentEntry, 0, len(contentItems)) for _, contentItem := range contentItems { contentKey, err := hexutil.Decode(contentItem[0]) if err != nil {