Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
7b32c113
Commit
7b32c113
authored
Sep 11, 2014
by
Matt Bell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: Refactored node initialization
parent
76b9a99e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
24 deletions
+35
-24
core/core.go
core/core.go
+35
-24
No files found.
core/core.go
View file @
7b32c113
...
...
@@ -69,13 +69,32 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
return
nil
,
err
}
var
swap
*
bitswap
.
BitSwap
local
,
err
:=
initIdentity
(
cfg
)
if
err
!=
nil
{
return
nil
,
err
}
var
(
net
*
swarm
.
Swarm
// TODO: refactor so we can use IpfsRouting interface instead of being DHT-specific
route
*
dht
.
IpfsDHT
swap
*
bitswap
.
BitSwap
)
if
online
{
swap
,
err
=
loadBitswap
(
cfg
,
d
)
net
=
swarm
.
NewSwarm
(
local
)
err
=
net
.
Listen
()
if
err
!=
nil
{
return
nil
,
err
}
route
=
dht
.
NewDHT
(
local
,
net
,
d
)
route
.
Start
()
swap
=
bitswap
.
NewBitSwap
(
local
,
net
,
d
,
route
)
swap
.
SetStrategy
(
bitswap
.
YesManStrategy
)
go
initConnections
(
cfg
,
route
)
}
bs
,
err
:=
bserv
.
NewBlockService
(
d
,
swap
)
...
...
@@ -85,19 +104,24 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
dag
:=
&
merkledag
.
DAGService
{
Blocks
:
bs
}
n
:=
&
IpfsNode
{
return
&
IpfsNode
{
Config
:
cfg
,
PeerMap
:
&
peer
.
Map
{},
Datastore
:
d
,
Blocks
:
bs
,
DAG
:
dag
,
Resolver
:
&
path
.
Resolver
{
DAG
:
dag
},
}
return
n
,
nil
BitSwap
:
swap
,
Identity
:
local
,
Routing
:
route
,
},
nil
}
func
loadBitswap
(
cfg
*
config
.
Config
,
d
ds
.
Datastore
)
(
*
bitswap
.
BitSwap
,
error
)
{
func
initIdentity
(
cfg
*
config
.
Config
)
(
*
peer
.
Peer
,
error
)
{
if
len
(
cfg
.
Identity
.
PeerID
)
==
0
{
return
nil
,
errors
.
New
(
"No peer ID in config! (was ipfs init run?)"
)
}
maddr
,
err
:=
ma
.
NewMultiaddr
(
cfg
.
Identity
.
Address
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -113,26 +137,15 @@ func loadBitswap(cfg *config.Config, d ds.Datastore) (*bitswap.BitSwap, error) {
return
nil
,
err
}
local
:=
&
peer
.
Peer
{
return
&
peer
.
Peer
{
ID
:
peer
.
ID
(
b58
.
Decode
(
cfg
.
Identity
.
PeerID
)),
Addresses
:
[]
*
ma
.
Multiaddr
{
maddr
},
PrivKey
:
sk
,
PubKey
:
sk
.
GetPublic
(),
}
if
len
(
local
.
ID
)
==
0
{
return
nil
,
errors
.
New
(
"No peer ID in config! (was ipfs init run?)"
)
}
net
:=
swarm
.
NewSwarm
(
local
)
err
=
net
.
Listen
()
if
err
!=
nil
{
return
nil
,
err
}
route
:=
dht
.
NewDHT
(
local
,
net
,
d
)
route
.
Start
()
},
nil
}
func
initConnections
(
cfg
*
config
.
Config
,
route
*
dht
.
IpfsDHT
)
{
for
_
,
p
:=
range
cfg
.
Peers
{
maddr
,
err
:=
ma
.
NewMultiaddr
(
p
.
Address
)
if
err
!=
nil
{
...
...
@@ -145,8 +158,6 @@ func loadBitswap(cfg *config.Config, d ds.Datastore) (*bitswap.BitSwap, error) {
u
.
PErr
(
"Bootstrapping error: %v
\n
"
,
err
)
}
}
return
bitswap
.
NewBitSwap
(
local
,
net
,
d
,
route
),
nil
}
func
(
n
*
IpfsNode
)
PinDagNode
(
nd
*
merkledag
.
Node
)
error
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment