github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/core/discovery/reducer/proposal.go (about) 1 /* 2 * Copyright (C) 2019 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package reducer 19 20 import ( 21 "github.com/mysteriumnetwork/node/market" 22 ) 23 24 // ProviderID selects provider id value from proposal 25 func ProviderID(proposal market.ServiceProposal) interface{} { 26 return proposal.ProviderID 27 } 28 29 // ServiceType selects service type from proposal 30 func ServiceType(proposal market.ServiceProposal) interface{} { 31 return proposal.ServiceType 32 } 33 34 // Location selects service location from proposal 35 func Location(proposal market.ServiceProposal) interface{} { 36 return proposal.Location 37 } 38 39 // LocationCountry selects location country from proposal 40 func LocationCountry(proposal market.ServiceProposal) interface{} { 41 return proposal.Location.Country 42 } 43 44 // LocationType selects location type from proposal 45 func LocationType(proposal market.ServiceProposal) interface{} { 46 return proposal.Location.IPType 47 } 48 49 // AccessPolicy returns a matcher for checking if proposal allows given access policy 50 func AccessPolicy(id, source string) func(market.ServiceProposal) bool { 51 return func(proposal market.ServiceProposal) bool { 52 // These proposals accepts all access lists 53 if proposal.AccessPolicies == nil { 54 return false 55 } 56 57 var match bool 58 for _, policy := range *proposal.AccessPolicies { 59 match = (id == "" || policy.ID == id) && 60 (source == "" || policy.Source == source) 61 if match { 62 break 63 } 64 } 65 return match 66 } 67 } 68 69 // Unsupported filters out unsupported proposals 70 func Unsupported() func(market.ServiceProposal) bool { 71 return func(proposal market.ServiceProposal) bool { 72 return proposal.IsSupported() 73 } 74 }