Skip to content
Snippets Groups Projects
Select Git revision
  • 4545d868dd4f88fad5f86f9f01d1821cb5b2141d
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

hostPool.go

Blame
  • hostPool.go 13.40 KiB
    ///////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                          //
    //                                                                           //
    // Use of this source code is governed by a license that can be found in the //
    // LICENSE file                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    
    // Package gateway Handles functionality related to providing Gateway connect.Host objects
    // for message sending to the rest of the client repo
    // Used to minimize # of open connections on mobile clients
    
    package gateway
    
    import (
    	"encoding/binary"
    	"fmt"
    	"github.com/pkg/errors"
    	jww "github.com/spf13/jwalterweatherman"
    	"gitlab.com/elixxir/client/storage"
    	"gitlab.com/elixxir/comms/network"
    	"gitlab.com/elixxir/crypto/fastRNG"
    	"gitlab.com/xx_network/comms/connect"
    	"gitlab.com/xx_network/primitives/id"
    	"gitlab.com/xx_network/primitives/ndf"
    	"golang.org/x/net/context"
    	"io"
    	"math"
    	"strings"
    	"sync"
    	"time"
    )
    
    // List of errors that initiate a Host replacement
    var errorsList = []string{context.DeadlineExceeded.Error(), "connection refused", "host disconnected",
    	"transport is closing", "all SubConns are in TransientFailure", "Last try to connect",
    	ndf.NO_NDF, "Host is in cool down"}
    
    // HostManager Interface allowing storage and retrieval of Host objects
    type HostManager interface {
    	GetHost(hostId *id.ID) (*connect.Host, bool)
    	AddHost(hid *id.ID, address string, cert []byte, params connect.HostParams) (host *connect.Host, err error)
    	RemoveHost(hid *id.ID)
    }
    
    // HostPool Handles providing hosts to the Client
    type HostPool struct {
    	hostMap  map[id.ID]uint32 // map key to its index in the slice
    	hostList []*connect.Host  // each index in the slice contains the value
    	hostMux  sync.RWMutex     // Mutex for the above map/list combination
    
    	ndfMap map[id.ID]int // map gateway ID to its index in the ndf
    	ndf    *ndf.NetworkDefinition
    	ndfMux sync.RWMutex
    
    	poolParams     PoolParams
    	rng            *fastRNG.StreamGenerator
    	storage        *storage.Session
    	manager        HostManager
    	addGatewayChan chan network.NodeGateway
    }
    
    // PoolParams Allows configuration of HostPool parameters
    type PoolParams struct {
    	MaxPoolSize uint32 // Maximum number of Hosts in the HostPool
    	PoolSize    uint32 // Allows override of HostPool size. Set to zero for dynamic size calculation
    	// TODO: Move up a layer
    	ProxyAttempts uint32             // How many proxies will be used in event of send failure
    	HostParams    connect.HostParams // Parameters for the creation of new Host objects
    }