github.com/ipni/storetheindex@v0.8.30/assigner/config/assignment.go (about) 1 package config 2 3 import ( 4 "time" 5 6 sticfg "github.com/ipni/storetheindex/config" 7 ) 8 9 // Assignment holds addresses of indexers to assign publishers to, policy 10 // specifying which peers to allow announce messages from, and related 11 // settings. 12 type Assignment struct { 13 // FilterIPs, when true, removes any private, loopback, or unspecified IP 14 // addresses from provider and publisher addresses. 15 FilterIPs bool 16 // PoolInterval is how often to poll indexers for status. 17 PollInterval sticfg.Duration 18 // IndexerPool is the set of indexers the pool. 19 IndexerPool []Indexer 20 // Policy configures which peers are allowed and blocked. 21 Policy Policy 22 // PubSubTopic sets the topic name to which to subscribe for ingestion 23 // announcements. 24 PubSubTopic string 25 // PresetReplication is the number of pre-assigned indexers to assign a 26 // publisher to. See Indexer.PresetPeers. Any value < 1 defaults to 1. 27 PresetReplication int 28 // Replication is the number of indexers to assign each publisher to, when 29 // the publisher does not have a preset assignment. A value <= 0 assigns 30 // each publisher to one indexer. 31 Replication int 32 } 33 34 type Indexer struct { 35 // AdminURL is the base URL for the indexer's admin interface. 36 AdminURL string 37 // FindURL is the base URL for the indexer's find interface. 38 FindURL string 39 // IngestURL is the base URL for the indexer's ingest interface. 40 IngestURL string 41 // PresetPeers is a list of the peer IDs of pre-assigned publishers. A 42 // publisher is assigned to n of the indexers that has the publisher in 43 // PresetPeers, where n is PresetReplication. 44 PresetPeers []string 45 } 46 47 func NewIndexer() Indexer { 48 return Indexer{} 49 } 50 51 // NewDiscovery returns Discovery with values set to their defaults. 52 func NewAssignment() Assignment { 53 return Assignment{ 54 PollInterval: sticfg.Duration(5 * time.Minute), 55 Policy: NewPolicy(), 56 PubSubTopic: "/indexer/ingest/mainnet", 57 PresetReplication: 1, 58 Replication: 1, 59 } 60 } 61 62 // populateUnset replaces zero-values in the config with default values. 63 func (c *Assignment) populateUnset() { 64 def := NewAssignment() 65 66 if c.PollInterval == 0 { 67 c.PollInterval = def.PollInterval 68 } 69 if c.PubSubTopic == "" { 70 c.PubSubTopic = def.PubSubTopic 71 } 72 if c.PresetReplication <= 0 { 73 c.PresetReplication = def.PresetReplication 74 } 75 if c.Replication <= 0 { 76 c.Replication = def.Replication 77 } 78 }