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-unixfs
Commits
4f7856a4
Commit
4f7856a4
authored
Sep 10, 2014
by
Siraj Ravel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring naming conventions
parent
8dfb119f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
34 deletions
+38
-34
daemon/daemon.go
daemon/daemon.go
+28
-28
daemon/daemon_client.go
daemon/daemon_client.go
+10
-6
No files found.
daemon/daemon.go
View file @
4f7856a4
...
...
@@ -21,25 +21,25 @@ type DaemonListener struct {
closed
bool
}
func
NewDaemonListener
(
node
*
core
.
IpfsNode
,
addr
string
)
(
*
DaemonListener
,
error
)
{
type
Command
struct
{
Command
string
Args
[]
string
Opts
map
[
string
]
interface
{}
}
func
NewDaemonListener
(
Ipfsnode
*
core
.
IpfsNode
,
addr
string
)
(
*
DaemonListener
,
error
)
{
list
,
err
:=
net
.
Listen
(
"tcp"
,
addr
)
if
err
!=
nil
{
return
nil
,
err
}
fmt
.
Println
(
"
n
ew daemon listener."
)
fmt
.
Println
(
"
N
ew daemon listener
initialized
."
)
return
&
DaemonListener
{
node
:
node
,
node
:
Ipfs
node
,
list
:
list
,
},
nil
}
type
Command
struct
{
Command
string
Args
[]
string
Opts
map
[
string
]
interface
{}
}
func
NewCommand
()
*
Command
{
return
&
Command
{
Opts
:
make
(
map
[
string
]
interface
{}),
...
...
@@ -49,7 +49,7 @@ func NewCommand() *Command {
func
(
dl
*
DaemonListener
)
Listen
()
{
fmt
.
Println
(
"listen."
)
for
{
c
,
err
:=
dl
.
list
.
Accept
()
c
onn
,
err
:=
dl
.
list
.
Accept
()
fmt
.
Println
(
"Loop!"
)
if
err
!=
nil
{
if
!
dl
.
closed
{
...
...
@@ -57,27 +57,27 @@ func (dl *DaemonListener) Listen() {
}
return
}
go
dl
.
handleConnection
(
c
)
go
dl
.
handleConnection
(
c
onn
)
}
}
func
(
dl
*
DaemonListener
)
handleConnection
(
c
net
.
Conn
)
{
defer
c
.
Close
()
func
(
dl
*
DaemonListener
)
handleConnection
(
c
onn
net
.
Conn
)
{
defer
c
onn
.
Close
()
dec
:=
json
.
NewDecoder
(
c
)
dec
:=
json
.
NewDecoder
(
c
onn
)
var
com
Command
err
:=
dec
.
Decode
(
&
com
)
var
com
mand
Command
err
:=
dec
.
Decode
(
&
com
mand
)
if
err
!=
nil
{
fmt
.
Fprintln
(
c
,
err
)
fmt
.
Fprintln
(
c
onn
,
err
)
return
}
u
.
DOut
(
"Got command: %v
\n
"
,
com
)
ExecuteCommand
(
&
com
,
dl
.
node
,
c
)
u
.
DOut
(
"Got command: %v
\n
"
,
com
mand
)
ExecuteCommand
(
&
com
mand
,
dl
.
node
,
c
onn
)
}
func
ExecuteCommand
(
com
*
Command
,
n
*
core
.
IpfsNode
,
out
io
.
Writer
)
{
func
ExecuteCommand
(
com
*
Command
,
Ipfsnode
*
core
.
IpfsNode
,
out
io
.
Writer
)
{
u
.
DOut
(
"executing command: %s
\n
"
,
com
.
Command
)
switch
com
.
Command
{
case
"add"
:
...
...
@@ -86,7 +86,7 @@ func ExecuteCommand(com *Command, n *core.IpfsNode, out io.Writer) {
depth
=
-
1
}
for
_
,
path
:=
range
com
.
Args
{
_
,
err
:=
commands
.
AddPath
(
n
,
path
,
depth
)
_
,
err
:=
commands
.
AddPath
(
Ipfsnode
,
path
,
depth
)
if
err
!=
nil
{
fmt
.
Fprintf
(
out
,
"addFile error: %v
\n
"
,
err
)
continue
...
...
@@ -94,13 +94,13 @@ func ExecuteCommand(com *Command, n *core.IpfsNode, out io.Writer) {
}
case
"cat"
:
for
_
,
fn
:=
range
com
.
Args
{
nd
,
err
:=
n
.
Resolver
.
ResolvePath
(
fn
)
DAGnode
,
err
:=
Ipfsnode
.
Resolver
.
ResolvePath
(
fn
)
if
err
!=
nil
{
fmt
.
Fprintf
(
out
,
"catFile error: %v
\n
"
,
err
)
return
}
read
,
err
:=
dag
.
NewDagReader
(
nd
,
n
.
DAG
)
read
,
err
:=
dag
.
NewDagReader
(
nd
,
Ipfsnode
.
DAG
)
if
err
!=
nil
{
fmt
.
Fprintln
(
out
,
err
)
continue
...
...
@@ -114,9 +114,9 @@ func ExecuteCommand(com *Command, n *core.IpfsNode, out io.Writer) {
}
case
"ls"
:
for
_
,
fn
:=
range
com
.
Args
{
nd
,
err
:=
n
.
Resolver
.
ResolvePath
(
fn
)
DAGnode
,
err
:=
n
.
Resolver
.
ResolvePath
(
fn
)
if
err
!=
nil
{
fmt
.
Fprintf
(
out
,
"ls: %v
\n
"
,
err
)
fmt
.
Fprintf
(
out
,
"ls
error
: %v
\n
"
,
err
)
return
}
...
...
@@ -126,13 +126,13 @@ func ExecuteCommand(com *Command, n *core.IpfsNode, out io.Writer) {
}
case
"pin"
:
for
_
,
fn
:=
range
com
.
Args
{
nd
,
err
:=
n
.
Resolver
.
ResolvePath
(
fn
)
DAGnode
,
err
:=
Ipfsnode
.
Resolver
.
ResolvePath
(
fn
)
if
err
!=
nil
{
fmt
.
Fprintf
(
out
,
"pin: %v
\n
"
,
err
)
fmt
.
Fprintf
(
out
,
"pin
error
: %v
\n
"
,
err
)
return
}
err
=
n
.
PinDagNode
(
nd
)
err
=
Ipfsnode
.
PinDagNode
(
nd
)
if
err
!=
nil
{
fmt
.
Fprintf
(
out
,
"pin: %v
\n
"
,
err
)
return
...
...
daemon/daemon_client.go
View file @
4f7856a4
...
...
@@ -5,22 +5,26 @@ import (
"io"
"net"
"os"
"time"
"time"
)
func
SendCommand
(
com
*
Command
,
server
string
)
error
{
con
,
err
:=
net
.
DialTimeout
(
"tcp"
,
server
,
time
.
Millisecond
*
300
)
//connects to the address on the network with a timeout and encodes the connection into JSON
func
SendCommand
(
command
*
Command
,
server
string
)
error
{
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
server
,
time
.
Millisecond
*
300
)
if
err
!=
nil
{
return
err
}
enc
:=
json
.
NewEncoder
(
con
)
err
=
enc
.
Encode
(
com
)
enc
:=
json
.
NewEncoder
(
con
n
)
err
=
enc
.
Encode
(
com
mand
)
if
err
!=
nil
{
return
err
}
io
.
Copy
(
os
.
Stdout
,
con
)
io
.
Copy
(
os
.
Stdout
,
con
n
)
return
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