Skip to content

Commit 49112b6

Browse files
committed
feat(ipns): refactored IPNS package with lean records
1 parent 9298e31 commit 49112b6

File tree

21 files changed

+452
-1046
lines changed

21 files changed

+452
-1046
lines changed

client/rpc/name.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,20 @@ import (
1010
caopts "github.com/ipfs/boxo/coreiface/options"
1111
nsopts "github.com/ipfs/boxo/coreiface/options/namesys"
1212
"github.com/ipfs/boxo/coreiface/path"
13+
"github.com/ipfs/boxo/ipns"
1314
)
1415

1516
type NameAPI HttpApi
1617

1718
type ipnsEntry struct {
18-
JName string `json:"Name"`
19-
JValue string `json:"Value"`
20-
21-
path path.Path
22-
}
23-
24-
func (e *ipnsEntry) Name() string {
25-
return e.JName
19+
Name string `json:"Name"`
20+
Value string `json:"Value"`
2621
}
2722

28-
func (e *ipnsEntry) Value() path.Path {
29-
return e.path
30-
}
31-
32-
func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.NamePublishOption) (iface.IpnsEntry, error) {
23+
func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.NamePublishOption) (ipns.Name, error) {
3324
options, err := caopts.NamePublishOptions(opts...)
3425
if err != nil {
35-
return nil, err
26+
return ipns.Name{}, err
3627
}
3728

3829
req := api.core().Request("name/publish", p.String()).
@@ -47,10 +38,9 @@ func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.Nam
4738

4839
var out ipnsEntry
4940
if err := req.Exec(ctx, &out); err != nil {
50-
return nil, err
41+
return ipns.Name{}, err
5142
}
52-
out.path = path.New(out.JValue)
53-
return &out, out.path.IsValid()
43+
return ipns.NameFromString(out.Name)
5444
}
5545

5646
func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.NameResolveOption) (<-chan iface.IpnsResult, error) {

config/routing.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Router struct {
2828
Type RouterType
2929

3030
// Parameters are extra configuration that this router might need.
31-
// A common one for reframe router is "Endpoint".
31+
// A common one for HTTP router is "Endpoint".
3232
Parameters interface{}
3333
}
3434

@@ -81,8 +81,6 @@ func (r *RouterParser) UnmarshalJSON(b []byte) error {
8181
switch out.Type {
8282
case RouterTypeHTTP:
8383
p = &HTTPRouterParams{}
84-
case RouterTypeReframe:
85-
p = &ReframeRouterParams{}
8684
case RouterTypeDHT:
8785
p = &DHTRouterParams{}
8886
case RouterTypeSequential:
@@ -106,7 +104,6 @@ func (r *RouterParser) UnmarshalJSON(b []byte) error {
106104
type RouterType string
107105

108106
const (
109-
RouterTypeReframe RouterType = "reframe" // More info here: https://github.com/ipfs/specs/tree/main/reframe . Actually deprecated.
110107
RouterTypeHTTP RouterType = "http" // HTTP JSON API for delegated routing systems (IPIP-337).
111108
RouterTypeDHT RouterType = "dht" // DHT router.
112109
RouterTypeSequential RouterType = "sequential" // Router helper to execute several routers sequentially.
@@ -133,12 +130,6 @@ const (
133130

134131
var MethodNameList = []MethodName{MethodNameProvide, MethodNameFindPeers, MethodNameFindProviders, MethodNameGetIPNS, MethodNamePutIPNS}
135132

136-
type ReframeRouterParams struct {
137-
// Endpoint is the URL where the routing implementation will point to get the information.
138-
// Usually used for reframe Routers.
139-
Endpoint string
140-
}
141-
142133
type HTTPRouterParams struct {
143134
// Endpoint is the URL where the routing implementation will point to get the information.
144135
Endpoint string

config/routing_test.go

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ func TestRouterParameters(t *testing.T) {
2323
PublicIPNetwork: false,
2424
},
2525
}},
26-
"router-reframe": {Router{
27-
Type: RouterTypeReframe,
28-
Parameters: ReframeRouterParams{
29-
Endpoint: "reframe-endpoint",
30-
},
31-
}},
3226
"router-parallel": {Router{
3327
Type: RouterTypeParallel,
3428
Parameters: ComposableRouterParams{
@@ -39,7 +33,7 @@ func TestRouterParameters(t *testing.T) {
3933
IgnoreErrors: true,
4034
},
4135
{
42-
RouterName: "router-reframe",
36+
RouterName: "router-dht",
4337
Timeout: Duration{10 * time.Second},
4438
IgnoreErrors: false,
4539
ExecuteAfter: &OptionalDuration{&sec},
@@ -58,7 +52,7 @@ func TestRouterParameters(t *testing.T) {
5852
IgnoreErrors: true,
5953
},
6054
{
61-
RouterName: "router-reframe",
55+
RouterName: "router-dht",
6256
Timeout: Duration{10 * time.Second},
6357
IgnoreErrors: false,
6458
},
@@ -69,7 +63,7 @@ func TestRouterParameters(t *testing.T) {
6963
},
7064
Methods: Methods{
7165
MethodNameFindPeers: {
72-
RouterName: "router-reframe",
66+
RouterName: "router-dht",
7367
},
7468
MethodNameFindProviders: {
7569
RouterName: "router-dht",
@@ -99,95 +93,48 @@ func TestRouterParameters(t *testing.T) {
9993
dhtp := r2.Routers["router-dht"].Parameters
10094
require.IsType(&DHTRouterParams{}, dhtp)
10195

102-
rp := r2.Routers["router-reframe"].Parameters
103-
require.IsType(&ReframeRouterParams{}, rp)
104-
10596
sp := r2.Routers["router-sequential"].Parameters
10697
require.IsType(&ComposableRouterParams{}, sp)
10798

10899
pp := r2.Routers["router-parallel"].Parameters
109100
require.IsType(&ComposableRouterParams{}, pp)
110101
}
111102

112-
func TestRouterMissingParameters(t *testing.T) {
113-
require := require.New(t)
114-
115-
r := Routing{
116-
Type: NewOptionalString("custom"),
117-
Routers: map[string]RouterParser{
118-
"router-wrong-reframe": {Router{
119-
Type: RouterTypeReframe,
120-
Parameters: DHTRouterParams{
121-
Mode: "auto",
122-
AcceleratedDHTClient: true,
123-
PublicIPNetwork: false,
124-
},
125-
}},
126-
},
127-
Methods: Methods{
128-
MethodNameFindPeers: {
129-
RouterName: "router-wrong-reframe",
130-
},
131-
MethodNameFindProviders: {
132-
RouterName: "router-wrong-reframe",
133-
},
134-
MethodNameGetIPNS: {
135-
RouterName: "router-wrong-reframe",
136-
},
137-
MethodNameProvide: {
138-
RouterName: "router-wrong-reframe",
139-
},
140-
MethodNamePutIPNS: {
141-
RouterName: "router-wrong-reframe",
142-
},
143-
},
144-
}
145-
146-
out, err := json.Marshal(r)
147-
require.NoError(err)
148-
149-
r2 := &Routing{}
150-
151-
err = json.Unmarshal(out, r2)
152-
require.NoError(err)
153-
require.Empty(r2.Routers["router-wrong-reframe"].Parameters.(*ReframeRouterParams).Endpoint)
154-
}
155-
156103
func TestMethods(t *testing.T) {
157104
require := require.New(t)
158105

159106
methodsOK := Methods{
160107
MethodNameFindPeers: {
161-
RouterName: "router-wrong-reframe",
108+
RouterName: "router-wrong",
162109
},
163110
MethodNameFindProviders: {
164-
RouterName: "router-wrong-reframe",
111+
RouterName: "router-wrong",
165112
},
166113
MethodNameGetIPNS: {
167-
RouterName: "router-wrong-reframe",
114+
RouterName: "router-wrong",
168115
},
169116
MethodNameProvide: {
170-
RouterName: "router-wrong-reframe",
117+
RouterName: "router-wrong",
171118
},
172119
MethodNamePutIPNS: {
173-
RouterName: "router-wrong-reframe",
120+
RouterName: "router-wrong",
174121
},
175122
}
176123

177124
require.NoError(methodsOK.Check())
178125

179126
methodsMissing := Methods{
180127
MethodNameFindPeers: {
181-
RouterName: "router-wrong-reframe",
128+
RouterName: "router-wrong",
182129
},
183130
MethodNameGetIPNS: {
184-
RouterName: "router-wrong-reframe",
131+
RouterName: "router-wrong",
185132
},
186133
MethodNameProvide: {
187-
RouterName: "router-wrong-reframe",
134+
RouterName: "router-wrong",
188135
},
189136
MethodNamePutIPNS: {
190-
RouterName: "router-wrong-reframe",
137+
RouterName: "router-wrong",
191138
},
192139
}
193140

core/commands/dht_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func TestKeyTranslation(t *testing.T) {
1313
pid := test.RandPeerIDFatal(t)
1414
pkname := namesys.PkKeyForID(pid)
15-
ipnsname := ipns.RecordKey(pid)
15+
ipnsname := ipns.NameFromPeer(pid).RoutingKey()
1616

1717
pkk, err := escapeDhtKey("/pk/" + pid.Pretty())
1818
if err != nil {
@@ -28,7 +28,7 @@ func TestKeyTranslation(t *testing.T) {
2828
t.Fatal("keys didn't match!")
2929
}
3030

31-
if ipnsk != ipnsname {
31+
if ipnsk != string(ipnsname) {
3232
t.Fatal("keys didn't match!")
3333
}
3434
}

0 commit comments

Comments
 (0)