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:
Kishan Sagathiya 2018-10-14 22:42:50 +05:30
parent 2e66720486
commit fdb573c96f
7 changed files with 50 additions and 6 deletions

View File

@ -6,8 +6,9 @@ import (
"fmt"
"time"
"github.com/ipfs/ipfs-cluster/config"
ma "github.com/multiformats/go-multiaddr"
"github.com/ipfs/ipfs-cluster/config"
)
const configKey = "ipfsproxy"
@ -46,6 +47,19 @@ type Config struct {
// Server-side amount of time a Keep-Alive connection will be
// kept idle before being reused
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.

View File

@ -7,21 +7,22 @@ import (
"net"
"net/http"
"net/http/httputil"
"net/rpc"
"net/url"
"strconv"
"strings"
"sync"
"time"
rpc "github.com/hsanjuan/go-libp2p-gorpc"
cid "github.com/ipfs/go-cid"
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"
madns "github.com/multiformats/go-multiaddr-dns"
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

View File

@ -177,6 +177,7 @@ func (c *Cluster) setupRPCClients() {
c.tracker.SetClient(c.rpcClient)
c.ipfs.SetClient(c.rpcClient)
c.api.SetClient(c.rpcClient)
c.proxy.SetClient(c.rpcClient)
c.consensus.SetClient(c.rpcClient)
c.monitor.SetClient(c.rpcClient)
c.allocator.SetClient(c.rpcClient)

View File

@ -60,6 +60,7 @@ func makeConfigs() (*config.Manager, *cfgs) {
return cfg, &cfgs{
clusterCfg,
apiCfg,
ipfsproxyCfg,
ipfshttpCfg,
consensusCfg,
maptrackerCfg,

View File

@ -141,8 +141,8 @@ func createCluster(
cfgs.clusterCfg,
raftcon,
api,
connector,
proxy,
connector,
state,
tracker,
mon,

View File

@ -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
// IPFS daemon. It returns the fetched information.
// If the request fails, or the parsing fails, it

View File

@ -9,6 +9,7 @@ var logger = logging.Logger("cluster")
var LoggingFacilities = map[string]string{
"cluster": "INFO",
"restapi": "INFO",
"ipfsproxy": "INFO",
"ipfshttp": "INFO",
"monitor": "INFO",
"mapstate": "INFO",