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
09186366
Commit
09186366
authored
10 years ago
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(cmd/routingd) add executable
parent
c730e19b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
0 deletions
+121
-0
cmd/routingd/main.go
cmd/routingd/main.go
+121
-0
No files found.
cmd/routingd/main.go
0 → 100644
View file @
09186366
package
main
import
(
"flag"
"log"
"os"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
aws
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/crowdmob/goamz/aws"
s3
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/crowdmob/goamz/s3"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
syncds
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync"
core
"github.com/jbenet/go-ipfs/core"
corehttp
"github.com/jbenet/go-ipfs/core/corehttp"
"github.com/jbenet/go-ipfs/core/corerouting"
config
"github.com/jbenet/go-ipfs/repo/config"
fsrepo
"github.com/jbenet/go-ipfs/repo/fsrepo"
s3datastore
"github.com/jbenet/go-ipfs/thirdparty/s3-datastore"
ds2
"github.com/jbenet/go-ipfs/util/datastore2"
)
var
(
host
=
flag
.
String
(
"host"
,
"/ip4/0.0.0.0/tcp/8080"
,
"override the HTTP host listening address"
)
s3bucket
=
flag
.
String
(
"aws-bucket"
,
""
,
"S3 bucket for routing datastore"
)
s3region
=
flag
.
String
(
"aws-region"
,
aws
.
USWest2
.
Name
,
"S3 region"
)
nBitsForKeypair
=
flag
.
Int
(
"b"
,
1024
,
"number of bits for keypair (if repo is uninitialized)"
)
)
func
main
()
{
flag
.
Parse
()
if
*
s3bucket
==
""
{
log
.
Fatal
(
"bucket is required"
)
}
if
err
:=
run
();
err
!=
nil
{
log
.
Println
(
err
)
}
}
func
run
()
error
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
repoPath
,
err
:=
fsrepo
.
BestKnownPath
()
if
err
!=
nil
{
return
err
}
if
!
fsrepo
.
IsInitialized
(
repoPath
)
{
conf
,
err
:=
config
.
Init
(
os
.
Stdout
,
*
nBitsForKeypair
)
if
err
!=
nil
{
return
err
}
if
err
:=
fsrepo
.
Init
(
repoPath
,
conf
);
err
!=
nil
{
return
err
}
}
repo
:=
fsrepo
.
At
(
repoPath
)
if
err
:=
repo
.
Open
();
err
!=
nil
{
// owned by node
return
err
}
s3
,
err
:=
makeS3Datastore
()
if
err
!=
nil
{
return
err
}
enhanced
,
err
:=
enhanceDatastore
(
s3
)
if
err
!=
nil
{
return
err
}
node
,
err
:=
core
.
NewIPFSNode
(
ctx
,
core
.
OnlineWithOptions
(
repo
,
corerouting
.
GrandCentralServer
(
enhanced
),
core
.
DefaultHostOption
),
)
if
err
!=
nil
{
return
err
}
defer
node
.
Close
()
opts
:=
[]
corehttp
.
ServeOption
{}
return
corehttp
.
ListenAndServe
(
node
,
*
host
,
opts
...
)
// TODO rm
}
func
makeS3Datastore
()
(
*
s3datastore
.
S3Datastore
,
error
)
{
// FIXME get ENV through flags?
auth
,
err
:=
aws
.
EnvAuth
()
if
err
!=
nil
{
return
nil
,
err
}
s3c
:=
s3
.
New
(
auth
,
aws
.
Regions
[
*
s3region
])
b
:=
s3c
.
Bucket
(
*
s3bucket
)
exists
,
err
:=
b
.
Exists
(
"initialized"
)
// TODO lazily instantiate
if
err
!=
nil
{
return
nil
,
err
}
if
!
exists
{
if
err
:=
b
.
PutBucket
(
s3
.
PublicRead
);
err
!=
nil
{
switch
e
:=
err
.
(
type
)
{
case
*
s3
.
Error
:
log
.
Println
(
e
.
Code
)
default
:
return
nil
,
err
}
}
// TODO create the initial value
}
return
&
s3datastore
.
S3Datastore
{
Bucket
:
*
s3bucket
,
Client
:
s3c
,
},
nil
}
func
enhanceDatastore
(
d
datastore
.
Datastore
)
(
datastore
.
ThreadSafeDatastore
,
error
)
{
// TODO cache
return
ds2
.
CloserWrap
(
syncds
.
MutexWrap
(
d
)),
nil
}
This diff is collapsed.
Click to expand it.
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