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
efb75ee5
Commit
efb75ee5
authored
Jan 10, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: move add and cat to the core
parent
85401d53
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
29 deletions
+33
-29
core/core.go
core/core.go
+33
-0
test/epictest/core.go
test/epictest/core.go
+0
-29
No files found.
core/core.go
View file @
efb75ee5
...
@@ -3,6 +3,7 @@ package core
...
@@ -3,6 +3,7 @@ package core
import
(
import
(
"errors"
"errors"
"fmt"
"fmt"
"io"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
b58
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
b58
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
...
@@ -18,6 +19,8 @@ import (
...
@@ -18,6 +19,8 @@ import (
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
"github.com/jbenet/go-ipfs/exchange/offline"
"github.com/jbenet/go-ipfs/exchange/offline"
mount
"github.com/jbenet/go-ipfs/fuse/mount"
mount
"github.com/jbenet/go-ipfs/fuse/mount"
importer
"github.com/jbenet/go-ipfs/importer"
chunk
"github.com/jbenet/go-ipfs/importer/chunk"
merkledag
"github.com/jbenet/go-ipfs/merkledag"
merkledag
"github.com/jbenet/go-ipfs/merkledag"
namesys
"github.com/jbenet/go-ipfs/namesys"
namesys
"github.com/jbenet/go-ipfs/namesys"
ic
"github.com/jbenet/go-ipfs/p2p/crypto"
ic
"github.com/jbenet/go-ipfs/p2p/crypto"
...
@@ -29,6 +32,8 @@ import (
...
@@ -29,6 +32,8 @@ import (
pin
"github.com/jbenet/go-ipfs/pin"
pin
"github.com/jbenet/go-ipfs/pin"
routing
"github.com/jbenet/go-ipfs/routing"
routing
"github.com/jbenet/go-ipfs/routing"
dht
"github.com/jbenet/go-ipfs/routing/dht"
dht
"github.com/jbenet/go-ipfs/routing/dht"
uio
"github.com/jbenet/go-ipfs/unixfs/io"
u
"github.com/jbenet/go-ipfs/util"
ds2
"github.com/jbenet/go-ipfs/util/datastore2"
ds2
"github.com/jbenet/go-ipfs/util/datastore2"
debugerror
"github.com/jbenet/go-ipfs/util/debugerror"
debugerror
"github.com/jbenet/go-ipfs/util/debugerror"
eventlog
"github.com/jbenet/go-ipfs/util/eventlog"
eventlog
"github.com/jbenet/go-ipfs/util/eventlog"
...
@@ -274,6 +279,34 @@ func (n *IpfsNode) Bootstrap(ctx context.Context, peers []peer.PeerInfo) error {
...
@@ -274,6 +279,34 @@ func (n *IpfsNode) Bootstrap(ctx context.Context, peers []peer.PeerInfo) error {
return
nil
return
nil
}
}
// TODO we may not want to add these methods to the core. Maybe they should be
// defined as free functions in another package that use public fields on the
// node.
//
// e.g. reader, err := unix.Cat(node)
func
(
n
*
IpfsNode
)
Cat
(
k
u
.
Key
)
(
io
.
Reader
,
error
)
{
catterdag
:=
n
.
DAG
nodeCatted
,
err
:=
(
&
path
.
Resolver
{
catterdag
})
.
ResolvePath
(
k
.
String
())
if
err
!=
nil
{
return
nil
,
err
}
return
uio
.
NewDagReader
(
nodeCatted
,
catterdag
)
}
func
(
n
*
IpfsNode
)
Add
(
r
io
.
Reader
)
(
u
.
Key
,
error
)
{
nodeAdded
,
err
:=
importer
.
BuildDagFromReader
(
r
,
n
.
DAG
,
nil
,
chunk
.
DefaultSplitter
,
)
if
err
!=
nil
{
return
""
,
err
}
return
nodeAdded
.
Key
()
}
func
(
n
*
IpfsNode
)
loadID
()
error
{
func
(
n
*
IpfsNode
)
loadID
()
error
{
if
n
.
Identity
!=
""
{
if
n
.
Identity
!=
""
{
return
debugerror
.
New
(
"identity already loaded"
)
return
debugerror
.
New
(
"identity already loaded"
)
...
...
test/epictest/core.go
View file @
efb75ee5
package
epictest
package
epictest
import
(
import
(
"io"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
datastore
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
datastore
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
sync
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
sync
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
...
@@ -13,15 +11,10 @@ import (
...
@@ -13,15 +11,10 @@ import (
exchange
"github.com/jbenet/go-ipfs/exchange"
exchange
"github.com/jbenet/go-ipfs/exchange"
bitswap
"github.com/jbenet/go-ipfs/exchange/bitswap"
bitswap
"github.com/jbenet/go-ipfs/exchange/bitswap"
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
bsnet
"github.com/jbenet/go-ipfs/exchange/bitswap/network"
importer
"github.com/jbenet/go-ipfs/importer"
chunk
"github.com/jbenet/go-ipfs/importer/chunk"
merkledag
"github.com/jbenet/go-ipfs/merkledag"
merkledag
"github.com/jbenet/go-ipfs/merkledag"
host
"github.com/jbenet/go-ipfs/p2p/host"
host
"github.com/jbenet/go-ipfs/p2p/host"
peer
"github.com/jbenet/go-ipfs/p2p/peer"
peer
"github.com/jbenet/go-ipfs/p2p/peer"
path
"github.com/jbenet/go-ipfs/path"
dht
"github.com/jbenet/go-ipfs/routing/dht"
dht
"github.com/jbenet/go-ipfs/routing/dht"
uio
"github.com/jbenet/go-ipfs/unixfs/io"
util
"github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/util/datastore2"
"github.com/jbenet/go-ipfs/util/datastore2"
delay
"github.com/jbenet/go-ipfs/util/delay"
delay
"github.com/jbenet/go-ipfs/util/delay"
eventlog
"github.com/jbenet/go-ipfs/util/eventlog"
eventlog
"github.com/jbenet/go-ipfs/util/eventlog"
...
@@ -43,28 +36,6 @@ func (c *Core) Bootstrap(ctx context.Context, p peer.PeerInfo) error {
...
@@ -43,28 +36,6 @@ func (c *Core) Bootstrap(ctx context.Context, p peer.PeerInfo) error {
return
c
.
IpfsNode
.
Bootstrap
(
ctx
,
[]
peer
.
PeerInfo
{
p
})
return
c
.
IpfsNode
.
Bootstrap
(
ctx
,
[]
peer
.
PeerInfo
{
p
})
}
}
func
(
c
*
Core
)
Cat
(
k
util
.
Key
)
(
io
.
Reader
,
error
)
{
catterdag
:=
c
.
IpfsNode
.
DAG
nodeCatted
,
err
:=
(
&
path
.
Resolver
{
catterdag
})
.
ResolvePath
(
k
.
String
())
if
err
!=
nil
{
return
nil
,
err
}
return
uio
.
NewDagReader
(
nodeCatted
,
catterdag
)
}
func
(
c
*
Core
)
Add
(
r
io
.
Reader
)
(
util
.
Key
,
error
)
{
nodeAdded
,
err
:=
importer
.
BuildDagFromReader
(
r
,
c
.
IpfsNode
.
DAG
,
nil
,
chunk
.
DefaultSplitter
,
)
if
err
!=
nil
{
return
""
,
err
}
return
nodeAdded
.
Key
()
}
func
makeCore
(
ctx
context
.
Context
,
rf
RepoFactory
)
(
*
Core
,
error
)
{
func
makeCore
(
ctx
context
.
Context
,
rf
RepoFactory
)
(
*
Core
,
error
)
{
node
,
err
:=
rf
(
ctx
)
node
,
err
:=
rf
(
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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