github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/core/discovery/docs.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 /* 19 Package discovery is responsible for: 20 - handling discovery related communications 21 - keeping track of currently active proposals in local storage 22 - finding and filtering proposals in local storage 23 24 25 Proposal storage filtering can be done with ProposalReducer callbacks. 26 ProposalReducer is simple callback which is run against list of proposals. 27 Proposal storage filtering is performed with discovery.Finder: 28 ``` 29 finder := discovery.NewFinder(discovery.NewStorage()) 30 proposal, err := finder.GetProposal(market.ProposalID{ServiceType: "streaming", ProviderID: "0x1"}) 31 proposals, err = finder.MatchProposals(reducer.Equal(reducer.ProviderID, "0x2")) 32 ``` 33 34 - Most simple noop reducer: 35 ``` 36 finder.MatchProposals( 37 reducer.All(), 38 ) 39 ``` 40 - By proposal field: 41 ``` 42 finder.MatchProposals( 43 reducer.EqualString(reducer.ProviderID, "0x1"), 44 ) 45 ``` 46 - By custom callback: 47 ``` 48 finder.MatchProposals(func(proposal market.ServiceProposal) bool { 49 return proposal.ProviderID == "0x3" || proposal.ServiceType == "wireguard" 50 }) 51 ``` 52 - By several conditions: 53 ``` 54 finder.MatchProposals(reducer.And( 55 reducer.EqualString(reducer.ProviderID, "0x1"), 56 reducer.InString(reducer.ServiceType, "openvpn", "wireguard")), 57 reducer.AccessPolicy("mysterium", ""), 58 )) 59 ``` 60 - By nesting several conditions: 61 ``` 62 finder.MatchProposals(reducer.Or( 63 reducer.And( 64 reducer.EqualString(reducer.ServiceType, "wireguard"), 65 reducer.InString(reducer.Country, "US", "CA"), 66 reducer.EqualString(reducer.IPType, "residential"), 67 ), 68 reducer.And( 69 reducer.EqualString(reducer.ServiceType, "openvpn"), 70 reducer.Or( 71 reducer.EqualString(reducer.Country, "US")), 72 reducer.EqualString(reducer.Country, "CA")), 73 ), 74 reducer.Not(reducer.EqualString(reducer.IPType, "datacenter")), 75 ) 76 )) 77 ``` 78 */ 79 80 package discovery