cmd/swarm: Add --httpaddr flag (#14475)
Fixes #14474. Signed-off-by: Lewis Marshall <lewis@lmars.net>
This commit is contained in:
parent
bc75351edf
commit
4a2c17b1ab
|
@ -67,6 +67,10 @@ var (
|
||||||
Name: "bzzaccount",
|
Name: "bzzaccount",
|
||||||
Usage: "Swarm account key file",
|
Usage: "Swarm account key file",
|
||||||
}
|
}
|
||||||
|
SwarmListenAddrFlag = cli.StringFlag{
|
||||||
|
Name: "httpaddr",
|
||||||
|
Usage: "Swarm HTTP API listening interface",
|
||||||
|
}
|
||||||
SwarmPortFlag = cli.StringFlag{
|
SwarmPortFlag = cli.StringFlag{
|
||||||
Name: "bzzport",
|
Name: "bzzport",
|
||||||
Usage: "Swarm local http api port",
|
Usage: "Swarm local http api port",
|
||||||
|
@ -249,6 +253,7 @@ Cleans database of corrupted entries.
|
||||||
SwarmConfigPathFlag,
|
SwarmConfigPathFlag,
|
||||||
SwarmSwapEnabledFlag,
|
SwarmSwapEnabledFlag,
|
||||||
SwarmSyncEnabledFlag,
|
SwarmSyncEnabledFlag,
|
||||||
|
SwarmListenAddrFlag,
|
||||||
SwarmPortFlag,
|
SwarmPortFlag,
|
||||||
SwarmAccountFlag,
|
SwarmAccountFlag,
|
||||||
SwarmNetworkIdFlag,
|
SwarmNetworkIdFlag,
|
||||||
|
@ -345,6 +350,9 @@ func registerBzzService(ctx *cli.Context, stack *node.Node) {
|
||||||
if len(bzzport) > 0 {
|
if len(bzzport) > 0 {
|
||||||
bzzconfig.Port = bzzport
|
bzzconfig.Port = bzzport
|
||||||
}
|
}
|
||||||
|
if bzzaddr := ctx.GlobalString(SwarmListenAddrFlag.Name); bzzaddr != "" {
|
||||||
|
bzzconfig.ListenAddr = bzzaddr
|
||||||
|
}
|
||||||
swapEnabled := ctx.GlobalBool(SwarmSwapEnabledFlag.Name)
|
swapEnabled := ctx.GlobalBool(SwarmSwapEnabledFlag.Name)
|
||||||
syncEnabled := ctx.GlobalBoolT(SwarmSyncEnabledFlag.Name)
|
syncEnabled := ctx.GlobalBoolT(SwarmSyncEnabledFlag.Name)
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
port = "8500"
|
DefaultHTTPListenAddr = "127.0.0.1"
|
||||||
|
DefaultHTTPPort = "8500"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -49,6 +50,7 @@ type Config struct {
|
||||||
Swap *swap.SwapParams
|
Swap *swap.SwapParams
|
||||||
*network.SyncParams
|
*network.SyncParams
|
||||||
Path string
|
Path string
|
||||||
|
ListenAddr string
|
||||||
Port string
|
Port string
|
||||||
PublicKey string
|
PublicKey string
|
||||||
BzzKey string
|
BzzKey string
|
||||||
|
@ -76,7 +78,8 @@ func NewConfig(path string, contract common.Address, prvKey *ecdsa.PrivateKey, n
|
||||||
HiveParams: network.NewHiveParams(dirpath),
|
HiveParams: network.NewHiveParams(dirpath),
|
||||||
ChunkerParams: storage.NewChunkerParams(),
|
ChunkerParams: storage.NewChunkerParams(),
|
||||||
StoreParams: storage.NewStoreParams(dirpath),
|
StoreParams: storage.NewStoreParams(dirpath),
|
||||||
Port: port,
|
ListenAddr: DefaultHTTPListenAddr,
|
||||||
|
Port: DefaultHTTPPort,
|
||||||
Path: dirpath,
|
Path: dirpath,
|
||||||
Swap: swap.DefaultSwapParams(contract, prvKey),
|
Swap: swap.DefaultSwapParams(contract, prvKey),
|
||||||
PublicKey: pubkeyhex,
|
PublicKey: pubkeyhex,
|
||||||
|
|
|
@ -80,6 +80,7 @@ var (
|
||||||
false
|
false
|
||||||
],
|
],
|
||||||
"Path": "TMPDIR",
|
"Path": "TMPDIR",
|
||||||
|
"ListenAddr": "127.0.0.1",
|
||||||
"Port": "8500",
|
"Port": "8500",
|
||||||
"PublicKey": "0x045f5cfd26692e48d0017d380349bcf50982488bc11b5145f3ddf88b24924299048450542d43527fbe29a5cb32f38d62755393ac002e6bfdd71b8d7ba725ecd7a3",
|
"PublicKey": "0x045f5cfd26692e48d0017d380349bcf50982488bc11b5145f3ddf88b24924299048450542d43527fbe29a5cb32f38d62755393ac002e6bfdd71b8d7ba725ecd7a3",
|
||||||
"BzzKey": "0xe861964402c0b78e2d44098329b8545726f215afa737d803714a4338552fcb81",
|
"BzzKey": "0xe861964402c0b78e2d44098329b8545726f215afa737d803714a4338552fcb81",
|
||||||
|
|
|
@ -69,7 +69,6 @@ func StartHttpServer(api *api.Api, config *ServerConfig) {
|
||||||
hdlr := c.Handler(NewServer(api))
|
hdlr := c.Handler(NewServer(api))
|
||||||
|
|
||||||
go http.ListenAndServe(config.Addr, hdlr)
|
go http.ListenAndServe(config.Addr, hdlr)
|
||||||
log.Info(fmt.Sprintf("Swarm HTTP proxy started on localhost:%s", config.Addr))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer(api *api.Api) *Server {
|
func NewServer(api *api.Api) *Server {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
@ -166,13 +167,13 @@ Start is called when the stack is started
|
||||||
* TODO: start subservices like sword, swear, swarmdns
|
* TODO: start subservices like sword, swear, swarmdns
|
||||||
*/
|
*/
|
||||||
// implements the node.Service interface
|
// implements the node.Service interface
|
||||||
func (self *Swarm) Start(net *p2p.Server) error {
|
func (self *Swarm) Start(srv *p2p.Server) error {
|
||||||
connectPeer := func(url string) error {
|
connectPeer := func(url string) error {
|
||||||
node, err := discover.ParseNode(url)
|
node, err := discover.ParseNode(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid node URL: %v", err)
|
return fmt.Errorf("invalid node URL: %v", err)
|
||||||
}
|
}
|
||||||
net.AddPeer(node)
|
srv.AddPeer(node)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// set chequebook
|
// set chequebook
|
||||||
|
@ -189,8 +190,8 @@ func (self *Swarm) Start(net *p2p.Server) error {
|
||||||
|
|
||||||
log.Warn(fmt.Sprintf("Starting Swarm service"))
|
log.Warn(fmt.Sprintf("Starting Swarm service"))
|
||||||
self.hive.Start(
|
self.hive.Start(
|
||||||
discover.PubkeyID(&net.PrivateKey.PublicKey),
|
discover.PubkeyID(&srv.PrivateKey.PublicKey),
|
||||||
func() string { return net.ListenAddr },
|
func() string { return srv.ListenAddr },
|
||||||
connectPeer,
|
connectPeer,
|
||||||
)
|
)
|
||||||
log.Info(fmt.Sprintf("Swarm network started on bzz address: %v", self.hive.Addr()))
|
log.Info(fmt.Sprintf("Swarm network started on bzz address: %v", self.hive.Addr()))
|
||||||
|
@ -200,18 +201,17 @@ func (self *Swarm) Start(net *p2p.Server) error {
|
||||||
|
|
||||||
// start swarm http proxy server
|
// start swarm http proxy server
|
||||||
if self.config.Port != "" {
|
if self.config.Port != "" {
|
||||||
addr := ":" + self.config.Port
|
addr := net.JoinHostPort(self.config.ListenAddr, self.config.Port)
|
||||||
go httpapi.StartHttpServer(self.api, &httpapi.ServerConfig{
|
go httpapi.StartHttpServer(self.api, &httpapi.ServerConfig{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
CorsString: self.corsString,
|
CorsString: self.corsString,
|
||||||
})
|
})
|
||||||
}
|
log.Info(fmt.Sprintf("Swarm http proxy started on %v", addr))
|
||||||
|
|
||||||
log.Debug(fmt.Sprintf("Swarm http proxy started on port: %v", self.config.Port))
|
|
||||||
|
|
||||||
if self.corsString != "" {
|
if self.corsString != "" {
|
||||||
log.Debug(fmt.Sprintf("Swarm http proxy started with corsdomain: %v", self.corsString))
|
log.Debug(fmt.Sprintf("Swarm http proxy started with corsdomain: %v", self.corsString))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue