Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
configurable listen address
Browse files Browse the repository at this point in the history
  • Loading branch information
nustiueudinastea authored and aboodman committed Jun 22, 2020
1 parent 3905723 commit 487d045
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmd/noms/noms_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import (

func nomsServe(noms *kingpin.Application) (*kingpin.CmdClause, util.KingpinHandler) {
cmd := noms.Command("serve", "Serves a Noms database over HTTP.")
address := cmd.Flag("address", "address to listen on").Default("0.0.0.0").String()
port := cmd.Flag("port", "port to listen on").Default("8080").Int()
db := cmd.Arg("db", "database to work with - see Spelling Databases at https://github.com/attic-labs/noms/blob/master/doc/spelling.md").Required().String()

return cmd, func(_ string) int {
cfg := config.NewResolver()
cs, err := cfg.GetChunkStore(*db)
d.CheckError(err)
server := datas.NewRemoteDatabaseServer(cs, *port)
server := datas.NewRemoteDatabaseServer(cs, *address, *port)

// Shutdown server gracefully so that profile may be written
c := make(chan os.Signal, 1)
Expand Down
7 changes: 4 additions & 3 deletions go/datas/database_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type connectionState struct {

type RemoteDatabaseServer struct {
cs chunks.ChunkStore
address string
port int
l *net.Listener
csChan chan *connectionState
Expand All @@ -32,13 +33,13 @@ type RemoteDatabaseServer struct {
Ready func()
}

func NewRemoteDatabaseServer(cs chunks.ChunkStore, port int) *RemoteDatabaseServer {
func NewRemoteDatabaseServer(cs chunks.ChunkStore, address string, port int) *RemoteDatabaseServer {
dataVersion := cs.Version()
if constants.NomsVersion != dataVersion {
d.Panic("SDK version %s is incompatible with data of version %s", constants.NomsVersion, dataVersion)
}
return &RemoteDatabaseServer{
cs, port, nil, make(chan *connectionState, 16), false, func() {},
cs, address, port, nil, make(chan *connectionState, 16), false, func() {},
}
}

Expand Down Expand Up @@ -75,7 +76,7 @@ func Router(cs chunks.ChunkStore, prefix string) *httprouter.Router {
// Run blocks while the RemoteDatabaseServer is listening. Running on a separate go routine is supported.
func (s *RemoteDatabaseServer) Run() {

l, err := net.Listen("tcp", fmt.Sprintf(":%d", s.port))
l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.address, s.port))
d.Chk.NoError(err)
s.l = &l
_, port, err := net.SplitHostPort(l.Addr().String())
Expand Down
2 changes: 1 addition & 1 deletion go/perf/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (suite *PerfSuite) StartRemoteDatabase() (host string, stopFn func()) {
chunkStore = nbs.NewLocalStore(dbDir, 128*(1<<20))
}

server := datas.NewRemoteDatabaseServer(chunkStore, 0)
server := datas.NewRemoteDatabaseServer(chunkStore, "0.0.0.0", 0)
portChan := make(chan int)
server.Ready = func() { portChan <- server.Port() }
go server.Run()
Expand Down

0 comments on commit 487d045

Please sign in to comment.