@@ -56,16 +56,16 @@ func (p *IPNSPublisher) Publish(ctx context.Context, priv crypto.PrivKey, value
56
56
57
57
// IpnsDsKey returns a datastore key given an IPNS identifier (peer
58
58
// ID). Defines the storage key for IPNS records in the local datastore.
59
- func IpnsDsKey (id peer. ID ) ds.Key {
60
- return ds .NewKey ("/ipns/" + base32 .RawStdEncoding .EncodeToString ([]byte (id )))
59
+ func IpnsDsKey (name ipns. Name ) ds.Key {
60
+ return ds .NewKey ("/ipns/" + base32 .RawStdEncoding .EncodeToString ([]byte (name . Peer () )))
61
61
}
62
62
63
63
// ListPublished returns the latest IPNS records published by this node and
64
64
// their expiration times.
65
65
//
66
66
// This method will not search the routing system for records published by other
67
67
// nodes.
68
- func (p * IPNSPublisher ) ListPublished (ctx context.Context ) (map [peer. ID ]* ipns.Record , error ) {
68
+ func (p * IPNSPublisher ) ListPublished (ctx context.Context ) (map [ipns. Name ]* ipns.Record , error ) {
69
69
query , err := p .ds .Query (ctx , dsquery.Query {
70
70
Prefix : ipns .NamespacePrefix ,
71
71
})
@@ -74,7 +74,7 @@ func (p *IPNSPublisher) ListPublished(ctx context.Context) (map[peer.ID]*ipns.Re
74
74
}
75
75
defer query .Close ()
76
76
77
- records := make (map [peer. ID ]* ipns.Record )
77
+ records := make (map [ipns. Name ]* ipns.Record )
78
78
for {
79
79
select {
80
80
case result , ok := <- query .Next ():
@@ -100,7 +100,7 @@ func (p *IPNSPublisher) ListPublished(ctx context.Context) (map[peer.ID]*ipns.Re
100
100
log .Errorf ("ipns ds key invalid: %s" , result .Key )
101
101
continue
102
102
}
103
- records [peer .ID (pid )] = rec
103
+ records [ipns . NameFromPeer ( peer .ID (pid ) )] = rec
104
104
case <- ctx .Done ():
105
105
return nil , ctx .Err ()
106
106
}
@@ -112,24 +112,24 @@ func (p *IPNSPublisher) ListPublished(ctx context.Context) (map[peer.ID]*ipns.Re
112
112
//
113
113
// If `checkRouting` is true and we have no existing record, this method will
114
114
// check the routing system for any existing records.
115
- func (p * IPNSPublisher ) GetPublished (ctx context.Context , id peer. ID , checkRouting bool ) (* ipns.Record , error ) {
115
+ func (p * IPNSPublisher ) GetPublished (ctx context.Context , name ipns. Name , checkRouting bool ) (* ipns.Record , error ) {
116
116
ctx , cancel := context .WithTimeout (ctx , time .Second * 30 )
117
117
defer cancel ()
118
118
119
- value , err := p .ds .Get (ctx , IpnsDsKey (id ))
119
+ value , err := p .ds .Get (ctx , IpnsDsKey (name ))
120
120
switch err {
121
121
case nil :
122
122
case ds .ErrNotFound :
123
123
if ! checkRouting {
124
124
return nil , nil
125
125
}
126
- routingKey := ipns . NameFromPeer ( id ) .RoutingKey ()
126
+ routingKey := name .RoutingKey ()
127
127
value , err = p .routing .GetValue (ctx , string (routingKey ))
128
128
if err != nil {
129
129
// Not found or other network issue. Can't really do
130
130
// anything about this case.
131
131
if err != routing .ErrNotFound {
132
- log .Debugf ("error when determining the last published IPNS record for %s: %s" , id , err )
132
+ log .Debugf ("error when determining the last published IPNS record for %s: %s" , name , err )
133
133
}
134
134
135
135
return nil , nil
@@ -146,12 +146,13 @@ func (p *IPNSPublisher) updateRecord(ctx context.Context, k crypto.PrivKey, valu
146
146
if err != nil {
147
147
return nil , err
148
148
}
149
+ name := ipns .NameFromPeer (id )
149
150
150
151
p .mu .Lock ()
151
152
defer p .mu .Unlock ()
152
153
153
154
// get previous records sequence number
154
- rec , err := p .GetPublished (ctx , id , true )
155
+ rec , err := p .GetPublished (ctx , name , true )
155
156
if err != nil {
156
157
return nil , err
157
158
}
@@ -188,7 +189,7 @@ func (p *IPNSPublisher) updateRecord(ctx context.Context, k crypto.PrivKey, valu
188
189
}
189
190
190
191
// Put the new record.
191
- dsKey := IpnsDsKey (id )
192
+ dsKey := IpnsDsKey (name )
192
193
if err := p .ds .Put (ctx , dsKey , data ); err != nil {
193
194
return nil , err
194
195
}
0 commit comments