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
7596bcce
Commit
7596bcce
authored
Nov 15, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaned up ipfs init
parent
e857a5bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
60 deletions
+82
-60
cmd/ipfs2/init.go
cmd/ipfs2/init.go
+82
-60
No files found.
cmd/ipfs2/init.go
View file @
7596bcce
...
...
@@ -50,98 +50,71 @@ var initCmd = &cmds.Command{
nBitsForKeypair
=
4096
}
return
nil
,
doInit
(
req
.
Context
()
.
ConfigRoot
,
dspathOverride
,
force
,
nBitsForKeypair
)
return
doInit
(
req
.
Context
()
.
ConfigRoot
,
dspathOverride
,
force
,
nBitsForKeypair
)
},
}
var
errCannotInitConfigExists
=
errors
.
New
(
`ipfs configuration file already exists!
Reinitializing would overwrite your keys.
(use -f to force overwrite)
`
)
var
welcomeMsg
=
`Hello and Welcome to IPFS!
██╗██████╗ ███████╗███████╗
██║██╔══██╗██╔════╝██╔════╝
██║██████╔╝█████╗ ███████╗
██║██╔═══╝ ██╔══╝ ╚════██║
██║██║ ██║ ███████║
╚═╝╚═╝ ╚═╝ ╚══════╝
If you're seeing this, you have successfully installed
IPFS and are now interfacing with the ipfs merkledag!
For a short demo of what you can do, enter 'ipfs tour'
`
// TODO add default welcome hash: eaa68bedae247ed1e5bd0eb4385a3c0959b976e4
// NB: if dspath is not provided, it will be retrieved from the config
func
doInit
(
configRoot
string
,
dspathOverride
string
,
force
bool
,
nBitsForKeypair
int
)
error
{
func
doInit
(
configRoot
string
,
dspathOverride
string
,
force
bool
,
nBitsForKeypair
int
)
(
interface
{},
error
)
{
u
.
POut
(
"initializing ipfs node at %s
\n
"
,
configRoot
)
configFilename
,
err
:=
config
.
Filename
(
configRoot
)
if
err
!=
nil
{
return
errors
.
New
(
"Couldn't get home directory path"
)
return
nil
,
errors
.
New
(
"Couldn't get home directory path"
)
}
fi
,
err
:=
os
.
Lstat
(
configFilename
)
if
fi
!=
nil
||
(
err
!=
nil
&&
!
os
.
IsNotExist
(
err
))
{
if
!
force
{
// TODO multi-line string
return
errors
.
New
(
"ipfs configuration file already exists!
\n
Reinitializing would overwrite your keys.
\n
(use -f to force overwrite)"
)
return
nil
,
errCannotInitConfigExists
}
}
ds
,
err
:=
datastoreConfig
(
dspathOverride
)
if
err
!=
nil
{
return
err
}
identity
,
err
:=
identityConfig
(
nBitsForKeypair
)
if
err
!=
nil
{
return
err
}
conf
:=
config
.
Config
{
// setup the node addresses.
Addresses
:
config
.
Addresses
{
Swarm
:
"/ip4/0.0.0.0/tcp/4001"
,
API
:
"/ip4/127.0.0.1/tcp/5001"
,
},
Bootstrap
:
[]
*
config
.
BootstrapPeer
{
&
config
.
BootstrapPeer
{
// Use these hardcoded bootstrap peers for now.
// mars.i.ipfs.io
PeerID
:
"QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
,
Address
:
"/ip4/104.131.131.82/tcp/4001"
,
},
},
Datastore
:
ds
,
Identity
:
identity
,
// setup the node mount points.
Mounts
:
config
.
Mounts
{
IPFS
:
"/ipfs"
,
IPNS
:
"/ipns"
,
},
// tracking ipfs version used to generate the init folder and adding
// update checker default setting.
Version
:
config
.
VersionDefaultValue
(),
}
err
=
config
.
WriteConfigFile
(
configFilename
,
conf
)
conf
,
err
:=
initConfig
(
configFilename
,
dspathOverride
,
nBitsForKeypair
)
if
err
!=
nil
{
return
err
return
nil
,
err
}
nd
,
err
:=
core
.
NewIpfsNode
(
&
conf
,
false
)
nd
,
err
:=
core
.
NewIpfsNode
(
conf
,
false
)
if
err
!=
nil
{
return
err
return
nil
,
err
}
defer
nd
.
Close
()
// Set up default file
msg
:=
`Hello and Welcome to IPFS!
If you're seeing this, that means that you have successfully
installed ipfs and are now interfacing with the wonderful
world of DAGs and hashes!
`
reader
:=
bytes
.
NewBufferString
(
msg
)
reader
:=
bytes
.
NewBufferString
(
welcomeMsg
)
defnd
,
err
:=
imp
.
BuildDagFromReader
(
reader
,
nd
.
DAG
,
nd
.
Pinning
.
GetManual
(),
chunk
.
DefaultSplitter
)
if
err
!=
nil
{
return
err
return
nil
,
err
}
k
,
_
:=
defnd
.
Key
()
fmt
.
Printf
(
"Default file key: %s
\n
"
,
k
)
return
nil
fmt
.
Printf
(
"done.
\n
to test, enter: ipfs cat %s
\n
"
,
k
)
return
nil
,
nil
}
func
datastoreConfig
(
dspath
string
)
(
config
.
Datastore
,
error
)
{
...
...
@@ -171,6 +144,55 @@ func datastoreConfig(dspath string) (config.Datastore, error) {
return
ds
,
nil
}
func
initConfig
(
configFilename
string
,
dspathOverride
string
,
nBitsForKeypair
int
)
(
*
config
.
Config
,
error
)
{
ds
,
err
:=
datastoreConfig
(
dspathOverride
)
if
err
!=
nil
{
return
nil
,
err
}
identity
,
err
:=
identityConfig
(
nBitsForKeypair
)
if
err
!=
nil
{
return
nil
,
err
}
conf
:=
&
config
.
Config
{
// setup the node addresses.
Addresses
:
config
.
Addresses
{
Swarm
:
"/ip4/0.0.0.0/tcp/4001"
,
API
:
"/ip4/127.0.0.1/tcp/5001"
,
},
Bootstrap
:
[]
*
config
.
BootstrapPeer
{
&
config
.
BootstrapPeer
{
// Use these hardcoded bootstrap peers for now.
// mars.i.ipfs.io
PeerID
:
"QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ"
,
Address
:
"/ip4/104.131.131.82/tcp/4001"
,
},
},
Datastore
:
ds
,
Identity
:
identity
,
// setup the node mount points.
Mounts
:
config
.
Mounts
{
IPFS
:
"/ipfs"
,
IPNS
:
"/ipns"
,
},
// tracking ipfs version used to generate the init folder and adding
// update checker default setting.
Version
:
config
.
VersionDefaultValue
(),
}
if
err
:=
config
.
WriteConfigFile
(
configFilename
,
conf
);
err
!=
nil
{
return
nil
,
err
}
return
conf
,
nil
}
func
identityConfig
(
nbits
int
)
(
config
.
Identity
,
error
)
{
// TODO guard higher up
ident
:=
config
.
Identity
{}
...
...
@@ -178,7 +200,7 @@ func identityConfig(nbits int) (config.Identity, error) {
return
ident
,
errors
.
New
(
"Bitsize less than 1024 is considered unsafe."
)
}
fmt
.
Print
ln
(
"generating key pair..."
)
fmt
.
Print
f
(
"generating key pair..."
)
sk
,
pk
,
err
:=
ci
.
GenerateKeyPair
(
ci
.
RSA
,
nbits
)
if
err
!=
nil
{
return
ident
,
err
...
...
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