Issue #453 Extract the IPFS Proxy from ipfshttp
Adding more missing pieces in config Use the right package(not the inbuilt one) Setup rpc client for proxy in the cluster Add back SetClient and Shutdown into Connector as they are required to implement Component interface Add `ipfsproxy` as into list of logging identifier and add its default log level License: MIT Signed-off-by: Kishan Mohanbhai Sagathiya <kishansagathiya@gmail.com>
This commit is contained in:
parent
2e66720486
commit
fdb573c96f
|
@ -6,8 +6,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ipfs/ipfs-cluster/config"
|
|
||||||
ma "github.com/multiformats/go-multiaddr"
|
ma "github.com/multiformats/go-multiaddr"
|
||||||
|
|
||||||
|
"github.com/ipfs/ipfs-cluster/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
const configKey = "ipfsproxy"
|
const configKey = "ipfsproxy"
|
||||||
|
@ -46,6 +47,19 @@ type Config struct {
|
||||||
// Server-side amount of time a Keep-Alive connection will be
|
// Server-side amount of time a Keep-Alive connection will be
|
||||||
// kept idle before being reused
|
// kept idle before being reused
|
||||||
ProxyIdleTimeout time.Duration
|
ProxyIdleTimeout time.Duration
|
||||||
|
|
||||||
|
// IPFS Daemon HTTP Client POST timeout
|
||||||
|
IPFSRequestTimeout time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonConfig struct {
|
||||||
|
ProxyListenMultiaddress string `json:"proxy_listen_multiaddress"`
|
||||||
|
NodeMultiaddress string `json:"node_multiaddress"`
|
||||||
|
ProxyReadTimeout string `json:"proxy_read_timeout"`
|
||||||
|
ProxyReadHeaderTimeout string `json:"proxy_read_header_timeout"`
|
||||||
|
ProxyWriteTimeout string `json:"proxy_write_timeout"`
|
||||||
|
ProxyIdleTimeout string `json:"proxy_idle_timeout"`
|
||||||
|
IPFSRequestTimeout string `json:"ipfs_request_timeout"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigKey provides a human-friendly identifier for this type of Config.
|
// ConfigKey provides a human-friendly identifier for this type of Config.
|
||||||
|
|
|
@ -7,21 +7,22 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/rpc"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
rpc "github.com/hsanjuan/go-libp2p-gorpc"
|
||||||
cid "github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
"github.com/ipfs/ipfs-cluster/adder/adderutils"
|
|
||||||
"github.com/ipfs/ipfs-cluster/api"
|
|
||||||
"github.com/ipfs/ipfs-cluster/rpcutil"
|
|
||||||
peer "github.com/libp2p/go-libp2p-peer"
|
peer "github.com/libp2p/go-libp2p-peer"
|
||||||
madns "github.com/multiformats/go-multiaddr-dns"
|
madns "github.com/multiformats/go-multiaddr-dns"
|
||||||
manet "github.com/multiformats/go-multiaddr-net"
|
manet "github.com/multiformats/go-multiaddr-net"
|
||||||
|
|
||||||
|
"github.com/ipfs/ipfs-cluster/adder/adderutils"
|
||||||
|
"github.com/ipfs/ipfs-cluster/api"
|
||||||
|
"github.com/ipfs/ipfs-cluster/rpcutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DNSTimeout is used when resolving DNS multiaddresses in this module
|
// DNSTimeout is used when resolving DNS multiaddresses in this module
|
||||||
|
|
|
@ -177,6 +177,7 @@ func (c *Cluster) setupRPCClients() {
|
||||||
c.tracker.SetClient(c.rpcClient)
|
c.tracker.SetClient(c.rpcClient)
|
||||||
c.ipfs.SetClient(c.rpcClient)
|
c.ipfs.SetClient(c.rpcClient)
|
||||||
c.api.SetClient(c.rpcClient)
|
c.api.SetClient(c.rpcClient)
|
||||||
|
c.proxy.SetClient(c.rpcClient)
|
||||||
c.consensus.SetClient(c.rpcClient)
|
c.consensus.SetClient(c.rpcClient)
|
||||||
c.monitor.SetClient(c.rpcClient)
|
c.monitor.SetClient(c.rpcClient)
|
||||||
c.allocator.SetClient(c.rpcClient)
|
c.allocator.SetClient(c.rpcClient)
|
||||||
|
|
|
@ -60,6 +60,7 @@ func makeConfigs() (*config.Manager, *cfgs) {
|
||||||
return cfg, &cfgs{
|
return cfg, &cfgs{
|
||||||
clusterCfg,
|
clusterCfg,
|
||||||
apiCfg,
|
apiCfg,
|
||||||
|
ipfsproxyCfg,
|
||||||
ipfshttpCfg,
|
ipfshttpCfg,
|
||||||
consensusCfg,
|
consensusCfg,
|
||||||
maptrackerCfg,
|
maptrackerCfg,
|
||||||
|
|
|
@ -141,8 +141,8 @@ func createCluster(
|
||||||
cfgs.clusterCfg,
|
cfgs.clusterCfg,
|
||||||
raftcon,
|
raftcon,
|
||||||
api,
|
api,
|
||||||
connector,
|
|
||||||
proxy,
|
proxy,
|
||||||
|
connector,
|
||||||
state,
|
state,
|
||||||
tracker,
|
tracker,
|
||||||
mon,
|
mon,
|
||||||
|
|
|
@ -163,6 +163,32 @@ func (ipfs *Connector) run() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetClient makes the component ready to perform RPC
|
||||||
|
// requests.
|
||||||
|
func (ipfs *Connector) SetClient(c *rpc.Client) {
|
||||||
|
ipfs.rpcClient = c
|
||||||
|
ipfs.rpcReady <- struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shutdown stops any listeners and stops the component from taking
|
||||||
|
// any requests.
|
||||||
|
func (ipfs *Connector) Shutdown() error {
|
||||||
|
ipfs.shutdownLock.Lock()
|
||||||
|
defer ipfs.shutdownLock.Unlock()
|
||||||
|
|
||||||
|
if ipfs.shutdown {
|
||||||
|
logger.Debug("already shutdown")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ipfs.cancel()
|
||||||
|
close(ipfs.rpcReady)
|
||||||
|
|
||||||
|
ipfs.wg.Wait()
|
||||||
|
ipfs.shutdown = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// ID performs an ID request against the configured
|
// ID performs an ID request against the configured
|
||||||
// IPFS daemon. It returns the fetched information.
|
// IPFS daemon. It returns the fetched information.
|
||||||
// If the request fails, or the parsing fails, it
|
// If the request fails, or the parsing fails, it
|
||||||
|
|
|
@ -9,6 +9,7 @@ var logger = logging.Logger("cluster")
|
||||||
var LoggingFacilities = map[string]string{
|
var LoggingFacilities = map[string]string{
|
||||||
"cluster": "INFO",
|
"cluster": "INFO",
|
||||||
"restapi": "INFO",
|
"restapi": "INFO",
|
||||||
|
"ipfsproxy": "INFO",
|
||||||
"ipfshttp": "INFO",
|
"ipfshttp": "INFO",
|
||||||
"monitor": "INFO",
|
"monitor": "INFO",
|
||||||
"mapstate": "INFO",
|
"mapstate": "INFO",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user