Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
ea8683ac
提交
ea8683ac
authored
8月 20, 2016
作者:
Jeromy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
routing: rework interfaces to make separation easier
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
上级
7276fd84
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
42 行增加
和
28 行删除
+42
-28
ipfs_impl.go
exchange/bitswap/network/ipfs_impl.go
+2
-2
reprovide.go
exchange/reprovide/reprovide.go
+2
-2
namesys.go
namesys/namesys.go
+1
-1
publisher.go
namesys/publisher.go
+5
-5
repub.go
namesys/republisher/repub.go
+2
-2
routing.go
namesys/routing.go
+2
-2
routing.go
routing/routing.go
+28
-14
没有找到文件。
exchange/bitswap/network/ipfs_impl.go
浏览文件 @
ea8683ac
...
...
@@ -20,7 +20,7 @@ import (
var
log
=
logging
.
Logger
(
"bitswap_network"
)
// NewFromIpfsHost returns a BitSwapNetwork supported by underlying IPFS host
func
NewFromIpfsHost
(
host
host
.
Host
,
r
routing
.
Ipfs
Routing
)
BitSwapNetwork
{
func
NewFromIpfsHost
(
host
host
.
Host
,
r
routing
.
Content
Routing
)
BitSwapNetwork
{
bitswapNetwork
:=
impl
{
host
:
host
,
routing
:
r
,
...
...
@@ -36,7 +36,7 @@ func NewFromIpfsHost(host host.Host, r routing.IpfsRouting) BitSwapNetwork {
// NetMessage objects, into the bitswap network interface.
type
impl
struct
{
host
host
.
Host
routing
routing
.
Ipfs
Routing
routing
routing
.
Content
Routing
// inbound messages from the network are forwarded to the receiver
receiver
Receiver
...
...
exchange/reprovide/reprovide.go
浏览文件 @
ea8683ac
...
...
@@ -15,13 +15,13 @@ var log = logging.Logger("reprovider")
type
Reprovider
struct
{
// The routing system to provide values through
rsys
routing
.
Ipfs
Routing
rsys
routing
.
Content
Routing
// The backing store for blocks to be provided
bstore
blocks
.
Blockstore
}
func
NewReprovider
(
rsys
routing
.
Ipfs
Routing
,
bstore
blocks
.
Blockstore
)
*
Reprovider
{
func
NewReprovider
(
rsys
routing
.
Content
Routing
,
bstore
blocks
.
Blockstore
)
*
Reprovider
{
return
&
Reprovider
{
rsys
:
rsys
,
bstore
:
bstore
,
...
...
namesys/namesys.go
浏览文件 @
ea8683ac
...
...
@@ -26,7 +26,7 @@ type mpns struct {
}
// NewNameSystem will construct the IPFS naming system based on Routing
func
NewNameSystem
(
r
routing
.
IpfsRouting
,
ds
ds
.
Datastore
,
cachesize
int
)
NameSystem
{
func
NewNameSystem
(
r
routing
.
ValueStore
,
ds
ds
.
Datastore
,
cachesize
int
)
NameSystem
{
return
&
mpns
{
resolvers
:
map
[
string
]
resolver
{
"dns"
:
newDNSResolver
(),
...
...
namesys/publisher.go
浏览文件 @
ea8683ac
...
...
@@ -37,12 +37,12 @@ var PublishPutValTimeout = time.Minute
// ipnsPublisher is capable of publishing and resolving names to the IPFS
// routing system.
type
ipnsPublisher
struct
{
routing
routing
.
IpfsRouting
routing
routing
.
ValueStore
ds
ds
.
Datastore
}
// NewRoutingPublisher constructs a publisher for the IPFS Routing name system.
func
NewRoutingPublisher
(
route
routing
.
IpfsRouting
,
ds
ds
.
Datastore
)
*
ipnsPublisher
{
func
NewRoutingPublisher
(
route
routing
.
ValueStore
,
ds
ds
.
Datastore
)
*
ipnsPublisher
{
if
ds
==
nil
{
panic
(
"nil datastore"
)
}
...
...
@@ -134,7 +134,7 @@ func checkCtxTTL(ctx context.Context) (time.Duration, bool) {
return
d
,
ok
}
func
PutRecordToRouting
(
ctx
context
.
Context
,
k
ci
.
PrivKey
,
value
path
.
Path
,
seqnum
uint64
,
eol
time
.
Time
,
r
routing
.
IpfsRouting
,
id
peer
.
ID
)
error
{
func
PutRecordToRouting
(
ctx
context
.
Context
,
k
ci
.
PrivKey
,
value
path
.
Path
,
seqnum
uint64
,
eol
time
.
Time
,
r
routing
.
ValueStore
,
id
peer
.
ID
)
error
{
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
...
...
@@ -181,7 +181,7 @@ func waitOnErrChan(ctx context.Context, errs chan error) error {
}
}
func
PublishPublicKey
(
ctx
context
.
Context
,
r
routing
.
IpfsRouting
,
k
key
.
Key
,
pubk
ci
.
PubKey
)
error
{
func
PublishPublicKey
(
ctx
context
.
Context
,
r
routing
.
ValueStore
,
k
key
.
Key
,
pubk
ci
.
PubKey
)
error
{
log
.
Debugf
(
"Storing pubkey at: %s"
,
k
)
pkbytes
,
err
:=
pubk
.
Bytes
()
if
err
!=
nil
{
...
...
@@ -199,7 +199,7 @@ func PublishPublicKey(ctx context.Context, r routing.IpfsRouting, k key.Key, pub
return
nil
}
func
PublishEntry
(
ctx
context
.
Context
,
r
routing
.
IpfsRouting
,
ipnskey
key
.
Key
,
rec
*
pb
.
IpnsEntry
)
error
{
func
PublishEntry
(
ctx
context
.
Context
,
r
routing
.
ValueStore
,
ipnskey
key
.
Key
,
rec
*
pb
.
IpnsEntry
)
error
{
timectx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
PublishPutValTimeout
)
defer
cancel
()
...
...
namesys/republisher/repub.go
浏览文件 @
ea8683ac
...
...
@@ -31,7 +31,7 @@ var DefaultRebroadcastInterval = time.Hour * 4
const
DefaultRecordLifetime
=
time
.
Hour
*
24
type
Republisher
struct
{
r
routing
.
IpfsRouting
r
routing
.
ValueStore
ds
ds
.
Datastore
ps
pstore
.
Peerstore
...
...
@@ -44,7 +44,7 @@ type Republisher struct {
entries
map
[
peer
.
ID
]
struct
{}
}
func
NewRepublisher
(
r
routing
.
IpfsRouting
,
ds
ds
.
Datastore
,
ps
pstore
.
Peerstore
)
*
Republisher
{
func
NewRepublisher
(
r
routing
.
ValueStore
,
ds
ds
.
Datastore
,
ps
pstore
.
Peerstore
)
*
Republisher
{
return
&
Republisher
{
r
:
r
,
ps
:
ps
,
...
...
namesys/routing.go
浏览文件 @
ea8683ac
...
...
@@ -23,7 +23,7 @@ var log = logging.Logger("namesys")
// routingResolver implements NSResolver for the main IPFS SFS-like naming
type
routingResolver
struct
{
routing
routing
.
IpfsRouting
routing
routing
.
ValueStore
cache
*
lru
.
Cache
}
...
...
@@ -88,7 +88,7 @@ type cacheEntry struct {
// to implement SFS-like naming on top.
// cachesize is the limit of the number of entries in the lru cache. Setting it
// to '0' will disable caching.
func
NewRoutingResolver
(
route
routing
.
IpfsRouting
,
cachesize
int
)
*
routingResolver
{
func
NewRoutingResolver
(
route
routing
.
ValueStore
,
cachesize
int
)
*
routingResolver
{
if
route
==
nil
{
panic
(
"attempt to create resolver with nil routing system"
)
}
...
...
routing/routing.go
浏览文件 @
ea8683ac
...
...
@@ -14,11 +14,27 @@ import (
// ErrNotFound is returned when a search fails to find anything
var
ErrNotFound
=
errors
.
New
(
"routing: not found"
)
// IpfsRouting is the routing module interface
// It is implemented by things like DHTs, etc.
type
IpfsRouting
interface
{
// ContentRouting is a value provider layer of indirection. It is used to find
// information about who has what content.
type
ContentRouting
interface
{
// Announce that this node can provide value for given key
Provide
(
context
.
Context
,
key
.
Key
)
error
// Search for peers who are able to provide a given key
FindProvidersAsync
(
context
.
Context
,
key
.
Key
,
int
)
<-
chan
pstore
.
PeerInfo
}
// PeerRouting is a way to find information about certain peers.
// This can be implemented by a simple lookup table, a tracking server,
// or even a DHT.
type
PeerRouting
interface
{
// Find specific Peer
// FindPeer searches for a peer with given ID, returns a pstore.PeerInfo
// with relevant addresses.
FindPeer
(
context
.
Context
,
peer
.
ID
)
(
pstore
.
PeerInfo
,
error
)
}
type
ValueStore
interface
{
// Basic Put/Get
// PutValue adds value corresponding to given Key.
...
...
@@ -38,17 +54,15 @@ type IpfsRouting interface {
// As a result, a value of '1' is mostly useful for cases where the record
// in question has only one valid value (such as public keys)
GetValues
(
c
context
.
Context
,
k
key
.
Key
,
count
int
)
([]
RecvdVal
,
error
)
}
// Value provider layer of indirection.
// This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT.
// Announce that this node can provide value for given key
Provide
(
context
.
Context
,
key
.
Key
)
error
// Find specific Peer
// FindPeer searches for a peer with given ID, returns a pstore.PeerInfo
// with relevant addresses.
FindPeer
(
context
.
Context
,
peer
.
ID
)
(
pstore
.
PeerInfo
,
error
)
// IpfsRouting is the combination of different routing types that ipfs
// uses. It can be satisfied by a single item (such as a DHT) or multiple
// different pieces that are more optimized to each task.
type
IpfsRouting
interface
{
ContentRouting
PeerRouting
ValueStore
// Bootstrap allows callers to hint to the routing system to get into a
// Boostrapped state
...
...
@@ -74,7 +88,7 @@ func KeyForPublicKey(id peer.ID) key.Key {
return
key
.
Key
(
"/pk/"
+
string
(
id
))
}
func
GetPublicKey
(
r
IpfsRouting
,
ctx
context
.
Context
,
pkhash
[]
byte
)
(
ci
.
PubKey
,
error
)
{
func
GetPublicKey
(
r
ValueStore
,
ctx
context
.
Context
,
pkhash
[]
byte
)
(
ci
.
PubKey
,
error
)
{
if
dht
,
ok
:=
r
.
(
PubKeyFetcher
);
ok
{
// If we have a DHT as our routing system, use optimized fetcher
return
dht
.
GetPublicKey
(
ctx
,
peer
.
ID
(
pkhash
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论