Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
f0f88ade
提交
f0f88ade
authored
11月 28, 2016
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
completely remove go-key dep
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
上级
4e8015d7
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
55 行增加
和
124 行删除
+55
-124
builder.go
core/builder.go
+4
-4
publish.go
core/commands/publish.go
+5
-5
ipns_unix.go
fuse/ipns/ipns_unix.go
+8
-8
merkledag_test.go
merkledag/merkledag_test.go
+4
-5
node.go
merkledag/node.go
+1
-6
resolve_test.go
namesys/resolve_test.go
+4
-6
routing.go
namesys/routing.go
+5
-10
package.json
package.json
+0
-6
resolver_test.go
path/resolver_test.go
+7
-8
indirect.go
pin/indirect.go
+0
-39
set.go
pin/set.go
+0
-9
server.go
routing/supernode/server.go
+16
-16
server_test.go
routing/supernode/server_test.go
+1
-2
没有找到文件。
core/builder.go
浏览文件 @
f0f88ade
package
core
import
(
"context"
"crypto/rand"
"encoding/base64"
"errors"
...
...
@@ -17,14 +18,13 @@ import (
repo
"github.com/ipfs/go-ipfs/repo"
cfg
"github.com/ipfs/go-ipfs/repo/config"
context
"context"
retry
"gx/ipfs/QmPF5kxTYFkzhaY5LmkExood7aTTZBHWQC6cjdDQBuGrjp/retry-datastore"
metrics
"gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
goprocessctx
"gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess/context"
pstore
"gx/ipfs/QmXXCcQ7CLg5a81Ui9TTR35QcR4y7ZyihxwfjqaHfUVcVo/go-libp2p-peerstore"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
ds
"gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
dsync
"gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync"
peer
"gx/ipfs/QmfMmLGoKzCHDN7cGgk64PJr4iipzidDRME8HABSJqvmhC/go-libp2p-peer"
ci
"gx/ipfs/QmfWDLQjGjVe4fr5CoztYW2DYYjRysMJrFe1RCsXLPTf46/go-libp2p-crypto"
)
...
...
@@ -91,7 +91,7 @@ func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
return
nil
,
err
}
data
,
err
:=
pub
.
Hash
(
)
pid
,
err
:=
peer
.
IDFromPublicKey
(
pub
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -103,7 +103,7 @@ func defaultRepo(dstore repo.Datastore) (repo.Repo, error) {
c
.
Bootstrap
=
cfg
.
DefaultBootstrapAddresses
c
.
Addresses
.
Swarm
=
[]
string
{
"/ip4/0.0.0.0/tcp/4001"
}
c
.
Identity
.
PeerID
=
key
.
Key
(
data
)
.
B58String
()
c
.
Identity
.
PeerID
=
pid
.
Pretty
()
c
.
Identity
.
PrivKey
=
base64
.
StdEncoding
.
EncodeToString
(
privkeyb
)
return
&
repo
.
Mock
{
...
...
core/commands/publish.go
浏览文件 @
f0f88ade
package
commands
import
(
"context"
"errors"
"fmt"
"io"
"strings"
"time"
context
"context"
cmds
"github.com/ipfs/go-ipfs/commands"
core
"github.com/ipfs/go-ipfs/core"
path
"github.com/ipfs/go-ipfs/path"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
peer
"gx/ipfs/QmfMmLGoKzCHDN7cGgk64PJr4iipzidDRME8HABSJqvmhC/go-libp2p-peer"
crypto
"gx/ipfs/QmfWDLQjGjVe4fr5CoztYW2DYYjRysMJrFe1RCsXLPTf46/go-libp2p-crypto"
)
...
...
@@ -147,13 +147,13 @@ func publish(ctx context.Context, n *core.IpfsNode, k crypto.PrivKey, ref path.P
return
nil
,
err
}
hash
,
err
:=
k
.
GetPublic
()
.
Hash
(
)
pid
,
err
:=
peer
.
IDFromPrivateKey
(
k
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
IpnsEntry
{
Name
:
key
.
Key
(
hash
)
.
String
(),
Name
:
pid
.
Pretty
(),
Value
:
ref
.
String
(),
},
nil
}
fuse/ipns/ipns_unix.go
浏览文件 @
f0f88ade
...
...
@@ -5,22 +5,23 @@
package
ipns
import
(
"context"
"errors"
"fmt"
"os"
"context"
fuse
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse"
fs
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/bazil.org/fuse/fs"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
core
"github.com/ipfs/go-ipfs/core"
dag
"github.com/ipfs/go-ipfs/merkledag"
mfs
"github.com/ipfs/go-ipfs/mfs"
path
"github.com/ipfs/go-ipfs/path"
ft
"github.com/ipfs/go-ipfs/unixfs"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
cid
"gx/ipfs/QmcEcrBAMrwMyhSjXt4yfyPpzgSuV8HLHavnfmiKCSRqZU/go-cid"
peer
"gx/ipfs/QmfMmLGoKzCHDN7cGgk64PJr4iipzidDRME8HABSJqvmhC/go-libp2p-peer"
ci
"gx/ipfs/QmfWDLQjGjVe4fr5CoztYW2DYYjRysMJrFe1RCsXLPTf46/go-libp2p-crypto"
)
...
...
@@ -135,11 +136,11 @@ func CreateRoot(ipfs *core.IpfsNode, keys map[string]ci.PrivKey, ipfspath, ipnsp
roots
:=
make
(
map
[
string
]
*
keyRoot
)
links
:=
make
(
map
[
string
]
*
Link
)
for
alias
,
k
:=
range
keys
{
p
kh
,
err
:=
k
.
GetPublic
()
.
Hash
(
)
p
id
,
err
:=
peer
.
IDFromPrivateKey
(
k
)
if
err
!=
nil
{
return
nil
,
err
}
name
:=
key
.
Key
(
pkh
)
.
B58String
()
name
:=
pid
.
Pretty
()
kr
:=
&
keyRoot
{
k
:
k
,
alias
:
alias
}
fsn
,
err
:=
loadRoot
(
ipfs
.
Context
(),
kr
,
ipfs
,
name
)
...
...
@@ -241,13 +242,12 @@ func (r *Root) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
var
listing
[]
fuse
.
Dirent
for
alias
,
k
:=
range
r
.
Keys
{
pub
:=
k
.
GetPublic
()
hash
,
err
:=
pub
.
Hash
()
pid
,
err
:=
peer
.
IDFromPrivateKey
(
k
)
if
err
!=
nil
{
continue
}
ent
:=
fuse
.
Dirent
{
Name
:
key
.
Key
(
hash
)
.
B58String
(),
Name
:
pid
.
Pretty
(),
Type
:
fuse
.
DT_Dir
,
}
link
:=
fuse
.
Dirent
{
...
...
merkledag/merkledag_test.go
浏览文件 @
f0f88ade
...
...
@@ -22,7 +22,6 @@ import (
uio
"github.com/ipfs/go-ipfs/unixfs/io"
node
"gx/ipfs/QmUsVJ7AEnGyjX8YWnrwq9vmECVGwBQNAKPpgz5KSg8dcq/go-ipld-node"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
u
"gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
cid
"gx/ipfs/QmcEcrBAMrwMyhSjXt4yfyPpzgSuV8HLHavnfmiKCSRqZU/go-cid"
)
...
...
@@ -56,8 +55,8 @@ func TestNode(t *testing.T) {
}
h
:=
n
.
Multihash
()
k
:=
n
.
Key
()
if
k
!=
key
.
Key
(
h
)
{
k
:=
n
.
Cid
()
.
Hash
()
if
k
.
String
()
!=
h
.
String
(
)
{
t
.
Error
(
"Key is not equivalent to multihash"
)
}
else
{
fmt
.
Println
(
"key: "
,
k
)
...
...
@@ -84,7 +83,7 @@ func SubtestNodeStat(t *testing.T, n *ProtoNode) {
return
}
k
:=
n
.
Key
()
k
:=
n
.
Cid
()
expected
:=
node
.
NodeStat
{
NumLinks
:
len
(
n
.
Links
()),
...
...
@@ -92,7 +91,7 @@ func SubtestNodeStat(t *testing.T, n *ProtoNode) {
LinksSize
:
len
(
enc
)
-
len
(
n
.
Data
()),
// includes framing.
DataSize
:
len
(
n
.
Data
()),
CumulativeSize
:
int
(
cumSize
),
Hash
:
k
.
B58
String
(),
Hash
:
k
.
String
(),
}
actual
,
err
:=
n
.
Stat
()
...
...
merkledag/node.go
浏览文件 @
f0f88ade
...
...
@@ -6,7 +6,6 @@ import (
node
"gx/ipfs/QmUsVJ7AEnGyjX8YWnrwq9vmECVGwBQNAKPpgz5KSg8dcq/go-ipld-node"
mh
"gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
cid
"gx/ipfs/QmcEcrBAMrwMyhSjXt4yfyPpzgSuV8HLHavnfmiKCSRqZU/go-cid"
)
...
...
@@ -204,7 +203,7 @@ func (n *ProtoNode) Stat() (*node.NodeStat, error) {
}
return
&
node
.
NodeStat
{
Hash
:
n
.
Key
()
.
B58
String
(),
Hash
:
n
.
Cid
()
.
String
(),
NumLinks
:
len
(
n
.
links
),
BlockSize
:
len
(
enc
),
LinksSize
:
len
(
enc
)
-
len
(
n
.
data
),
// includes framing.
...
...
@@ -213,10 +212,6 @@ func (n *ProtoNode) Stat() (*node.NodeStat, error) {
},
nil
}
func
(
n
*
ProtoNode
)
Key
()
key
.
Key
{
return
key
.
Key
(
n
.
Multihash
())
}
func
(
n
*
ProtoNode
)
Loggable
()
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
"node"
:
n
.
String
(),
...
...
namesys/resolve_test.go
浏览文件 @
f0f88ade
package
namesys
import
(
"context"
"errors"
"testing"
"time"
context
"context"
path
"github.com/ipfs/go-ipfs/path"
mockrouting
"github.com/ipfs/go-ipfs/routing/mock"
testutil
"github.com/ipfs/go-ipfs/thirdparty/testutil"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
u
"gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
ds
"gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
dssync
"gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore/sync"
peer
"gx/ipfs/QmfMmLGoKzCHDN7cGgk64PJr4iipzidDRME8HABSJqvmhC/go-libp2p-peer"
...
...
@@ -36,13 +35,12 @@ func TestRoutingResolve(t *testing.T) {
t
.
Fatal
(
err
)
}
p
ubkb
,
err
:=
pubk
.
Bytes
(
)
p
id
,
err
:=
peer
.
IDFromPublicKey
(
pubk
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
pkhash
:=
u
.
Hash
(
pubkb
)
res
,
err
:=
resolver
.
Resolve
(
context
.
Background
(),
key
.
Key
(
pkhash
)
.
B58String
())
res
,
err
:=
resolver
.
Resolve
(
context
.
Background
(),
pid
.
Pretty
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
namesys/routing.go
浏览文件 @
f0f88ade
package
namesys
import
(
"context"
"fmt"
"strings"
"time"
"context"
lru
"gx/ipfs/QmVYxfoJQiZijTgPNHCHgHELvQpbsJNTg6Crmc3dQkj3yy/golang-lru"
mh
"gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash"
proto
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
pb
"github.com/ipfs/go-ipfs/namesys/pb"
path
"github.com/ipfs/go-ipfs/path"
routing
"gx/ipfs/QmUrCwTDvJgmBbJVHu1HGEyqDaod3dR6sEkZkpxZk4u47c/go-libp2p-routing"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
routing
"gx/ipfs/QmUrCwTDvJgmBbJVHu1HGEyqDaod3dR6sEkZkpxZk4u47c/go-libp2p-routing"
lru
"gx/ipfs/QmVYxfoJQiZijTgPNHCHgHELvQpbsJNTg6Crmc3dQkj3yy/golang-lru"
mh
"gx/ipfs/QmYDds3421prZgqKbLpEK7T9Aa2eVdQ7o3YarX1LVLdP2J/go-multihash"
proto
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
u
"gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
cid
"gx/ipfs/QmcEcrBAMrwMyhSjXt4yfyPpzgSuV8HLHavnfmiKCSRqZU/go-cid"
ci
"gx/ipfs/QmfWDLQjGjVe4fr5CoztYW2DYYjRysMJrFe1RCsXLPTf46/go-libp2p-crypto"
...
...
@@ -179,9 +177,6 @@ func (r *routingResolver) resolveOnce(ctx context.Context, name string) (path.Pa
}
}
hsh
,
_
:=
pubkey
.
Hash
()
log
.
Debugf
(
"pk hash = %s"
,
key
.
Key
(
hsh
))
// check sig with pk
if
ok
,
err
:=
pubkey
.
Verify
(
ipnsEntryDataForSig
(
entry
),
entry
.
GetSignature
());
err
!=
nil
||
!
ok
{
return
""
,
fmt
.
Errorf
(
"Invalid value. Not signed by PrivateKey corresponding to %v"
,
pubkey
)
...
...
package.json
浏览文件 @
f0f88ade
...
...
@@ -213,12 +213,6 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9"
,
"name"
:
"go-key"
,
"version"
:
"1.0.3"
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"QmU4VzzKNLJXJ72SedXBQKyf5Jo8W89iWpbWQjHn9qef8N"
,
"name"
:
"go-ds-flatfs"
,
"version"
:
"1.0.0"
...
...
path/resolver_test.go
浏览文件 @
f0f88ade
...
...
@@ -10,25 +10,23 @@ import (
path
"github.com/ipfs/go-ipfs/path"
node
"gx/ipfs/QmUsVJ7AEnGyjX8YWnrwq9vmECVGwBQNAKPpgz5KSg8dcq/go-ipld-node"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
util
"gx/ipfs/Qmb912gdngC1UWwTkhuW8knyRbcWeu5kqkxBpveLmW8bSr/go-ipfs-util"
)
func
randNode
()
(
*
merkledag
.
ProtoNode
,
key
.
Key
)
{
func
randNode
()
*
merkledag
.
ProtoNode
{
node
:=
new
(
merkledag
.
ProtoNode
)
node
.
SetData
(
make
([]
byte
,
32
))
util
.
NewTimeSeededRand
()
.
Read
(
node
.
Data
())
k
:=
node
.
Key
()
return
node
,
k
return
node
}
func
TestRecurivePathResolution
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
dagService
:=
dagmock
.
Mock
()
a
,
_
:=
randNode
()
b
,
_
:=
randNode
()
c
,
cKey
:=
randNode
()
a
:=
randNode
()
b
:=
randNode
()
c
:=
randNode
()
err
:=
b
.
AddNodeLink
(
"grandchild"
,
c
)
if
err
!=
nil
{
...
...
@@ -47,7 +45,7 @@ func TestRecurivePathResolution(t *testing.T) {
}
}
aKey
:=
a
.
Key
()
aKey
:=
a
.
Cid
()
segments
:=
[]
string
{
aKey
.
String
(),
"child"
,
"grandchild"
}
p
,
err
:=
path
.
FromSegments
(
"/ipfs/"
,
segments
...
)
...
...
@@ -61,6 +59,7 @@ func TestRecurivePathResolution(t *testing.T) {
t
.
Fatal
(
err
)
}
cKey
:=
c
.
Cid
()
key
:=
node
.
Cid
()
if
key
.
String
()
!=
cKey
.
String
()
{
t
.
Fatal
(
fmt
.
Errorf
(
...
...
pin/indirect.go
deleted
100644 → 0
浏览文件 @
4e8015d7
package
pin
import
(
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
)
type
indirectPin
struct
{
refCounts
map
[
key
.
Key
]
uint64
}
func
newIndirectPin
()
*
indirectPin
{
return
&
indirectPin
{
refCounts
:
make
(
map
[
key
.
Key
]
uint64
),
}
}
func
(
i
*
indirectPin
)
Increment
(
k
key
.
Key
)
{
i
.
refCounts
[
k
]
++
}
func
(
i
*
indirectPin
)
Decrement
(
k
key
.
Key
)
{
if
i
.
refCounts
[
k
]
==
0
{
log
.
Warningf
(
"pinning: bad call: asked to unpin nonexistent indirect key: %v"
,
k
)
return
}
i
.
refCounts
[
k
]
--
if
i
.
refCounts
[
k
]
==
0
{
delete
(
i
.
refCounts
,
k
)
}
}
func
(
i
*
indirectPin
)
HasKey
(
k
key
.
Key
)
bool
{
_
,
found
:=
i
.
refCounts
[
k
]
return
found
}
func
(
i
*
indirectPin
)
GetRefs
()
map
[
key
.
Key
]
uint64
{
return
i
.
refCounts
}
pin/set.go
浏览文件 @
f0f88ade
...
...
@@ -14,7 +14,6 @@ import (
"github.com/ipfs/go-ipfs/pin/internal/pb"
node
"gx/ipfs/QmUsVJ7AEnGyjX8YWnrwq9vmECVGwBQNAKPpgz5KSg8dcq/go-ipld-node"
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
cid
"gx/ipfs/QmcEcrBAMrwMyhSjXt4yfyPpzgSuV8HLHavnfmiKCSRqZU/go-cid"
)
...
...
@@ -308,11 +307,3 @@ func storeSet(ctx context.Context, dag merkledag.DAGService, cids []*cid.Cid, in
internalKeys
(
c
)
return
n
,
nil
}
func
copyRefcounts
(
orig
map
[
key
.
Key
]
uint64
)
map
[
key
.
Key
]
uint64
{
r
:=
make
(
map
[
key
.
Key
]
uint64
,
len
(
orig
))
for
k
,
v
:=
range
orig
{
r
[
k
]
=
v
}
return
r
}
routing/supernode/server.go
浏览文件 @
f0f88ade
package
supernode
import
(
"context"
"errors"
"fmt"
proxy
"github.com/ipfs/go-ipfs/routing/supernode/proxy"
dshelp
"github.com/ipfs/go-ipfs/thirdparty/ds-help"
context
"context"
pstore
"gx/ipfs/QmXXCcQ7CLg5a81Ui9TTR35QcR4y7ZyihxwfjqaHfUVcVo/go-libp2p-peerstore"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
proto
"gx/ipfs/QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV/gogo-protobuf/proto"
dhtpb
"gx/ipfs/QmaMRCpeKL34rdT7t3bEndrENbVdD6gcCZr3YdkDUk6jue/go-libp2p-kad-dht/pb"
datastore
"gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
...
...
@@ -55,7 +55,7 @@ func (s *Server) handleMessage(
switch
req
.
GetType
()
{
case
dhtpb
.
Message_GET_VALUE
:
rawRecord
,
err
:=
getRoutingRecord
(
s
.
routingBackend
,
key
.
Key
(
req
.
GetKey
()
))
rawRecord
,
err
:=
getRoutingRecord
(
s
.
routingBackend
,
req
.
GetKey
(
))
if
err
!=
nil
{
return
""
,
nil
}
...
...
@@ -69,7 +69,7 @@ func (s *Server) handleMessage(
// log.Event(ctx, "validationFailed", req, p)
// return "", nil
// }
putRoutingRecord
(
s
.
routingBackend
,
key
.
Key
(
req
.
GetKey
()
),
req
.
GetRecord
())
putRoutingRecord
(
s
.
routingBackend
,
req
.
GetKey
(
),
req
.
GetRecord
())
return
p
,
req
case
dhtpb
.
Message_FIND_NODE
:
...
...
@@ -89,7 +89,7 @@ func (s *Server) handleMessage(
if
providerID
==
p
{
store
:=
[]
*
dhtpb
.
Message_Peer
{
provider
}
storeProvidersToPeerstore
(
s
.
peerstore
,
p
,
store
)
if
err
:=
putRoutingProviders
(
s
.
routingBackend
,
key
.
Key
(
req
.
GetKey
()
),
store
);
err
!=
nil
{
if
err
:=
putRoutingProviders
(
s
.
routingBackend
,
req
.
GetKey
(
),
store
);
err
!=
nil
{
return
""
,
nil
}
}
else
{
...
...
@@ -99,7 +99,7 @@ func (s *Server) handleMessage(
return
""
,
nil
case
dhtpb
.
Message_GET_PROVIDERS
:
providers
,
err
:=
getRoutingProviders
(
s
.
routingBackend
,
key
.
Key
(
req
.
GetKey
()
))
providers
,
err
:=
getRoutingProviders
(
s
.
routingBackend
,
req
.
GetKey
(
))
if
err
!=
nil
{
return
""
,
nil
}
...
...
@@ -116,8 +116,8 @@ func (s *Server) handleMessage(
var
_
proxy
.
RequestHandler
=
&
Server
{}
var
_
proxy
.
Proxy
=
&
Server
{}
func
getRoutingRecord
(
ds
datastore
.
Datastore
,
k
key
.
Key
)
(
*
pb
.
Record
,
error
)
{
dskey
:=
k
.
DsKey
(
)
func
getRoutingRecord
(
ds
datastore
.
Datastore
,
k
string
)
(
*
pb
.
Record
,
error
)
{
dskey
:=
dshelp
.
NewKeyFromBinary
(
k
)
val
,
err
:=
ds
.
Get
(
dskey
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -133,12 +133,12 @@ func getRoutingRecord(ds datastore.Datastore, k key.Key) (*pb.Record, error) {
return
&
record
,
nil
}
func
putRoutingRecord
(
ds
datastore
.
Datastore
,
k
key
.
Key
,
value
*
pb
.
Record
)
error
{
func
putRoutingRecord
(
ds
datastore
.
Datastore
,
k
string
,
value
*
pb
.
Record
)
error
{
data
,
err
:=
proto
.
Marshal
(
value
)
if
err
!=
nil
{
return
err
}
dskey
:=
k
.
DsKey
(
)
dskey
:=
dshelp
.
NewKeyFromBinary
(
k
)
// TODO namespace
if
err
:=
ds
.
Put
(
dskey
,
data
);
err
!=
nil
{
return
err
...
...
@@ -146,8 +146,8 @@ func putRoutingRecord(ds datastore.Datastore, k key.Key, value *pb.Record) error
return
nil
}
func
putRoutingProviders
(
ds
datastore
.
Datastore
,
k
key
.
Key
,
newRecords
[]
*
dhtpb
.
Message_Peer
)
error
{
log
.
Event
(
context
.
Background
(),
"putRoutingProviders"
,
&
k
)
func
putRoutingProviders
(
ds
datastore
.
Datastore
,
k
string
,
newRecords
[]
*
dhtpb
.
Message_Peer
)
error
{
log
.
Event
(
context
.
Background
(),
"putRoutingProviders"
)
oldRecords
,
err
:=
getRoutingProviders
(
ds
,
k
)
if
err
!=
nil
{
return
err
...
...
@@ -185,8 +185,8 @@ func storeProvidersToPeerstore(ps pstore.Peerstore, p peer.ID, providers []*dhtp
}
}
func
getRoutingProviders
(
ds
datastore
.
Datastore
,
k
key
.
Key
)
([]
*
dhtpb
.
Message_Peer
,
error
)
{
e
:=
log
.
EventBegin
(
context
.
Background
(),
"getProviders"
,
&
k
)
func
getRoutingProviders
(
ds
datastore
.
Datastore
,
k
string
)
([]
*
dhtpb
.
Message_Peer
,
error
)
{
e
:=
log
.
EventBegin
(
context
.
Background
(),
"getProviders"
)
defer
e
.
Done
()
var
providers
[]
*
dhtpb
.
Message_Peer
if
v
,
err
:=
ds
.
Get
(
providerKey
(
k
));
err
==
nil
{
...
...
@@ -201,8 +201,8 @@ func getRoutingProviders(ds datastore.Datastore, k key.Key) ([]*dhtpb.Message_Pe
return
providers
,
nil
}
func
providerKey
(
k
key
.
Key
)
datastore
.
Key
{
return
datastore
.
KeyWithNamespaces
([]
string
{
"routing"
,
"providers"
,
k
.
String
()
})
func
providerKey
(
k
string
)
datastore
.
Key
{
return
datastore
.
KeyWithNamespaces
([]
string
{
"routing"
,
"providers"
,
k
})
}
func
verify
(
ps
pstore
.
Peerstore
,
r
*
pb
.
Record
)
error
{
...
...
routing/supernode/server_test.go
浏览文件 @
f0f88ade
...
...
@@ -3,14 +3,13 @@ package supernode
import
(
"testing"
key
"gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
dhtpb
"gx/ipfs/QmaMRCpeKL34rdT7t3bEndrENbVdD6gcCZr3YdkDUk6jue/go-libp2p-kad-dht/pb"
datastore
"gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
)
func
TestPutProviderDoesntResultInDuplicates
(
t
*
testing
.
T
)
{
routingBackend
:=
datastore
.
NewMapDatastore
()
k
:=
key
.
Key
(
"foo"
)
k
:=
"foo"
put
:=
[]
*
dhtpb
.
Message_Peer
{
convPeer
(
"bob"
,
"127.0.0.1/tcp/4001"
),
convPeer
(
"alice"
,
"10.0.0.10/tcp/4001"
),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论