github.com/Finschia/finschia-sdk@v0.48.1/baseapp/p2p.go (about) 1 package baseapp 2 3 // This file exists because Tendermint allows the application to control which peers it connects to. 4 // This is for an interesting idea -- allow the application to control the peer layer/ topology! 5 // It would be really exciting to mix web of trust and expander-graph style primitives 6 // for how information gets disseminated. 7 // However the API surface for this to make sense isn't really well exposed / thought through, 8 // so this file mostly acts as confusing boilerplate. 9 10 import ( 11 abci "github.com/tendermint/tendermint/abci/types" 12 13 sdk "github.com/Finschia/finschia-sdk/types" 14 sdkerrors "github.com/Finschia/finschia-sdk/types/errors" 15 ) 16 17 type peerFilters struct { 18 addrPeerFilter sdk.PeerFilter // filter peers by address and port 19 idPeerFilter sdk.PeerFilter // filter peers by node ID 20 } 21 22 // FilterPeerByAddrPort filters peers by address/port. 23 func (app *BaseApp) FilterPeerByAddrPort(info string) abci.ResponseQuery { 24 if app.addrPeerFilter != nil { 25 return app.addrPeerFilter(info) 26 } 27 28 return abci.ResponseQuery{} 29 } 30 31 // FilterPeerByID filters peers by node ID. 32 func (app *BaseApp) FilterPeerByID(info string) abci.ResponseQuery { 33 if app.idPeerFilter != nil { 34 return app.idPeerFilter(info) 35 } 36 37 return abci.ResponseQuery{} 38 } 39 40 func handleQueryP2P(app *BaseApp, path []string) abci.ResponseQuery { 41 // "/p2p" prefix for p2p queries 42 if len(path) < 4 { 43 return sdkerrors.QueryResultWithDebug( 44 sdkerrors.Wrap( 45 sdkerrors.ErrUnknownRequest, "path should be p2p filter <addr|id> <parameter>", 46 ), app.trace) 47 } 48 49 var resp abci.ResponseQuery 50 51 cmd, typ, arg := path[1], path[2], path[3] 52 switch cmd { 53 case "filter": 54 switch typ { 55 case "addr": 56 resp = app.FilterPeerByAddrPort(arg) 57 58 case "id": 59 resp = app.FilterPeerByID(arg) 60 } 61 62 default: 63 resp = sdkerrors.QueryResultWithDebug(sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, "expected second parameter to be 'filter'"), app.trace) 64 } 65 66 return resp 67 }