Giter Club home page Giter Club logo

Comments (8)

SamYuan1990 avatar SamYuan1990 commented on September 5, 2024

may I know more about the use case?
as channel config is "open" for everyone join this channel to get. Hence the anchor peers' information are published through channel config.
For example, org1 has 2 peers. peer1 is published to other orgs for endorsement usage as anchor peer? peer2 is not listed in the channel config.
Hence,
for org1, as org1 admin knows those two peers, is it necessary to org1 admin to have this feature?
and maybe for security reason, org1 don't want to expose peer2 to org2. Hence ... I suppose by default, there some limitations about topic discussed in this issue.

from fabric-admin-sdk.

bestbeforetoday avatar bestbeforetoday commented on September 5, 2024

A PeerMembershipQuery using the discovery service can return all the network organizations and their member peers.

from fabric-admin-sdk.

1gezhanghao avatar 1gezhanghao commented on September 5, 2024

may I know more about the use case? as channel config is "open" for everyone join this channel to get. Hence the anchor peers' information are published through channel config. For example, org1 has 2 peers. peer1 is published to other orgs for endorsement usage as anchor peer? peer2 is not listed in the channel config. Hence, for org1, as org1 admin knows those two peers, is it necessary to org1 admin to have this feature? and maybe for security reason, org1 don't want to expose peer2 to org2. Hence ... I suppose by default, there some limitations about topic discussed in this issue.

For security reasons, it is reasonable for Org 1 not to expose its non-anchor nodes to other Org.
Org 1 should have a simple one-time acquisition method to know which of its nodes are in the same ledger, instead of querying each peer node to confirm.

from fabric-admin-sdk.

SamYuan1990 avatar SamYuan1990 commented on September 5, 2024

may I know more about the use case? as channel config is "open" for everyone join this channel to get. Hence the anchor peers' information are published through channel config. For example, org1 has 2 peers. peer1 is published to other orgs for endorsement usage as anchor peer? peer2 is not listed in the channel config. Hence, for org1, as org1 admin knows those two peers, is it necessary to org1 admin to have this feature? and maybe for security reason, org1 don't want to expose peer2 to org2. Hence ... I suppose by default, there some limitations about topic discussed in this issue.

For security reasons, it is reasonable for Org 1 not to expose its non-anchor nodes to other Org. Org 1 should have a simple one-time acquisition method to know which of its nodes are in the same ledger, instead of querying each peer node to confirm.

could you please try the api as @bestbeforetoday's suggestion?

from fabric-admin-sdk.

1gezhanghao avatar 1gezhanghao commented on September 5, 2024

may I know more about the use case? as channel config is "open" for everyone join this channel to get. Hence the anchor peers' information are published through channel config. For example, org1 has 2 peers. peer1 is published to other orgs for endorsement usage as anchor peer? peer2 is not listed in the channel config. Hence, for org1, as org1 admin knows those two peers, is it necessary to org1 admin to have this feature? and maybe for security reason, org1 don't want to expose peer2 to org2. Hence ... I suppose by default, there some limitations about topic discussed in this issue.

For security reasons, it is reasonable for Org 1 not to expose its non-anchor nodes to other Org. Org 1 should have a simple one-time acquisition method to know which of its nodes are in the same ledger, instead of querying each peer node to confirm.

could you please try the api as @bestbeforetoday's suggestion?

yes, it worked, the result json as follows.

{
    "peers_by_org":{
        "CqMSP":{
            "peers":[
                {
                    "state_info":{
                        "payload":"GAV6bxIUCKjFnMn364myFxCUgJ/K9+uJshcaIOOqEE3pENasJBeEcKePpyd4CewXtmPPwnO0v7GwPrX4IiAuUxNhlDl6sh6uN/3g+ai/xa7gaOcSn1ebTGtxs9fBfCoTCAEaDwoKX2xpZmVjeWNsZRIBMQ==",
                        "signature":"MEUCIQDGQY0QL7JyAwDLn6sIfuCemdOXH6nD7ICd8X8fkjo0LgIgQkz86KFEIXa3WvbjKjlXtqqbNO3G5SgihRAQO7eEPzY="
                    },
                    "membership_info":{
                        "payload":"GAEqTQo9ChlwZWVyMS5jcS5leGFtcGxlLmNvbTo3MDUxGiDjqhBN6RDWrCQXhHCnj6cneAnsF7Zjz8JztL+xsD61+BIMCNrR3bXP64myFxAb",
                        "signature":"MEQCICQ63RER7207ig9oEf6XZOHSENuPozK1TKpUP53ahqMFAiBAoTv9WRyMKCTGDSM4AKtxIdaJ2cyLlHDVarCsuhOPZQ=="
                    },
                    "identity":"CgVDcU1TUBLNBy0tLS0tQkVHSU4gQ0VSVElGSUNBVEUtLS0tLQpNSUlDb0RDQ0FrZWdBd0lCQWdJVVlBS0Z5L2JZWlNmMWR4UGxjODROUnhIYW1OTXdDZ1lJS29aSXpqMEVBd0l3CmFERUxNQWtHQTFVRUJoTUNRMDR4RVRBUEJnT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01N2NLZE5uUEZLOVRHbG4rS1BtdSsxOEwwWDhUZlgKUlZkZ2t3PT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo="
                }
            ]
        }
    }
}

the peer endpoint is in membership_info's payload, the payload's proto struct is gossip.GossipMessage,
the Content of gossip.GossipMessage is *gossip.GossipMessage_AliveMsg
json result as follows

{
    "AliveMsg": {
        "membership": {
            "endpoint": "peer0.cq.example.com:7051",
            "pki_id": "k67w32SfrfzhaW7Gp/fz00gi2rh99K3HO3iOa63g17M="
        },
        "timestamp": {
            "inc_num": 1685515440265200767,
            "seq_num": 1903
        }
    }
}

i will give the implements code for this

from fabric-admin-sdk.

1gezhanghao avatar 1gezhanghao commented on September 5, 2024

implements code as follows

package discovery                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
import (                                                                                                                                                                                                                                                       
        "context"                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
        "github.com/hyperledger/fabric-admin-sdk/pkg/identity"                                                                                                                                                                                                 
        "github.com/hyperledger/fabric-protos-go-apiv2/discovery"                                                                                                                                                                                              
        "github.com/hyperledger/fabric-protos-go-apiv2/msp"                                                                                                                                                                                                    
        "google.golang.org/grpc"                                                                                                                                                                                                                               
        "google.golang.org/protobuf/proto"                                                                                                                                                                                                                     
)                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
func PeerMembershipQuery(ctx context.Context, conn *grpc.ClientConn, signer identity.SigningIdentity, channel string) (*discovery.PeerMembershipResult, error) {                                                                                                                    
        id := &msp.SerializedIdentity{                                                                                                                                                                                                                         
                Mspid:   signer.MspID(),                                                                                                                                                                                                                       
                IdBytes: signer.Credentials(),                                                                                                                                                                                                                 
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        idBytes, err := proto.Marshal(id)                                                                                                                                                                                                                      
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        querys := []*discovery.Query{                                                                                                                                                                                                                          
                &discovery.Query{                                                                                                                                                                                                                              
                        Channel: channel,                                                                                                                                                                                                                      
                        Query: &discovery.Query_PeerQuery{                                                                                                                                                                                                     
                                PeerQuery: &discovery.PeerMembershipQuery{                                                                                                                                                                                     
                                        Filter: nil,                                                                                                                                                                                                           
                                },                                                                                                                                                                                                                             
                        },                                                                                                                                                                                                                                     
                },                                                                                                                                                                                                                                             
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        request := &discovery.Request{                                                                                                                                                                                                                         
                Authentication: &discovery.AuthInfo{                                                                                                                                                                                                           
                        ClientIdentity:    idBytes,                                                                                                                                                                                                            
                        ClientTlsCertHash: signer.Credentials(),                                                                                                                                                                                               
                },                                                                                                                                                                                                                                             
                Queries: querys,                                                                                                                                                                                                                               
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        payload, err := proto.Marshal(request)                                                                                                                                                                                                                 
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        sig, err := signer.Sign(payload)                                                                                                                                                                                                                       
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        signedRequest := discovery.SignedRequest{                                                                                                                                                                                                              
                Payload:   payload,                                                                                                                                                                                                                            
                Signature: sig,                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        cli := discovery.NewDiscoveryClient(conn)                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
        rs, err := cli.Discover(ctx, &signedRequest)                                                                                                                                                                                          
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        for _, qrs := range rs.Results {                                                                                                                                                                                                                       
                return qrs.GetMembers(), nil                                                                                                                                                                                                                   
        }                                                                                                                                                                                                                                                      
        return nil, nil                                                                                                                                                                                                                                        
}

from fabric-admin-sdk.

SamYuan1990 avatar SamYuan1990 commented on September 5, 2024

implements code as follows

package discovery                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
import (                                                                                                                                                                                                                                                       
        "context"                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
        "github.com/hyperledger/fabric-admin-sdk/pkg/identity"                                                                                                                                                                                                 
        "github.com/hyperledger/fabric-protos-go-apiv2/discovery"                                                                                                                                                                                              
        "github.com/hyperledger/fabric-protos-go-apiv2/msp"                                                                                                                                                                                                    
        "google.golang.org/grpc"                                                                                                                                                                                                                               
        "google.golang.org/protobuf/proto"                                                                                                                                                                                                                     
)                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
func PeerMembershipQuery(ctx context.Context, conn *grpc.ClientConn, signer identity.SigningIdentity, channel string) (*discovery.PeerMembershipResult, error) {                                                                                                                    
        id := &msp.SerializedIdentity{                                                                                                                                                                                                                         
                Mspid:   signer.MspID(),                                                                                                                                                                                                                       
                IdBytes: signer.Credentials(),                                                                                                                                                                                                                 
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        idBytes, err := proto.Marshal(id)                                                                                                                                                                                                                      
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        querys := []*discovery.Query{                                                                                                                                                                                                                          
                &discovery.Query{                                                                                                                                                                                                                              
                        Channel: channel,                                                                                                                                                                                                                      
                        Query: &discovery.Query_PeerQuery{                                                                                                                                                                                                     
                                PeerQuery: &discovery.PeerMembershipQuery{                                                                                                                                                                                     
                                        Filter: nil,                                                                                                                                                                                                           
                                },                                                                                                                                                                                                                             
                        },                                                                                                                                                                                                                                     
                },                                                                                                                                                                                                                                             
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        request := &discovery.Request{                                                                                                                                                                                                                         
                Authentication: &discovery.AuthInfo{                                                                                                                                                                                                           
                        ClientIdentity:    idBytes,                                                                                                                                                                                                            
                        ClientTlsCertHash: signer.Credentials(),                                                                                                                                                                                               
                },                                                                                                                                                                                                                                             
                Queries: querys,                                                                                                                                                                                                                               
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        payload, err := proto.Marshal(request)                                                                                                                                                                                                                 
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        sig, err := signer.Sign(payload)                                                                                                                                                                                                                       
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        signedRequest := discovery.SignedRequest{                                                                                                                                                                                                              
                Payload:   payload,                                                                                                                                                                                                                            
                Signature: sig,                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        cli := discovery.NewDiscoveryClient(conn)                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
        rs, err := cli.Discover(ctx, &signedRequest)                                                                                                                                                                                          
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        for _, qrs := range rs.Results {                                                                                                                                                                                                                       
                return qrs.GetMembers(), nil                                                                                                                                                                                                                   
        }                                                                                                                                                                                                                                                      
        return nil, nil                                                                                                                                                                                                                                        
}

could you please open a PR with your contribution?

from fabric-admin-sdk.

1gezhanghao avatar 1gezhanghao commented on September 5, 2024

implements code as follows

package discovery                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
import (                                                                                                                                                                                                                                                       
        "context"                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
        "github.com/hyperledger/fabric-admin-sdk/pkg/identity"                                                                                                                                                                                                 
        "github.com/hyperledger/fabric-protos-go-apiv2/discovery"                                                                                                                                                                                              
        "github.com/hyperledger/fabric-protos-go-apiv2/msp"                                                                                                                                                                                                    
        "google.golang.org/grpc"                                                                                                                                                                                                                               
        "google.golang.org/protobuf/proto"                                                                                                                                                                                                                     
)                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
func PeerMembershipQuery(ctx context.Context, conn *grpc.ClientConn, signer identity.SigningIdentity, channel string) (*discovery.PeerMembershipResult, error) {                                                                                                                    
        id := &msp.SerializedIdentity{                                                                                                                                                                                                                         
                Mspid:   signer.MspID(),                                                                                                                                                                                                                       
                IdBytes: signer.Credentials(),                                                                                                                                                                                                                 
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        idBytes, err := proto.Marshal(id)                                                                                                                                                                                                                      
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        querys := []*discovery.Query{                                                                                                                                                                                                                          
                &discovery.Query{                                                                                                                                                                                                                              
                        Channel: channel,                                                                                                                                                                                                                      
                        Query: &discovery.Query_PeerQuery{                                                                                                                                                                                                     
                                PeerQuery: &discovery.PeerMembershipQuery{                                                                                                                                                                                     
                                        Filter: nil,                                                                                                                                                                                                           
                                },                                                                                                                                                                                                                             
                        },                                                                                                                                                                                                                                     
                },                                                                                                                                                                                                                                             
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        request := &discovery.Request{                                                                                                                                                                                                                         
                Authentication: &discovery.AuthInfo{                                                                                                                                                                                                           
                        ClientIdentity:    idBytes,                                                                                                                                                                                                            
                        ClientTlsCertHash: signer.Credentials(),                                                                                                                                                                                               
                },                                                                                                                                                                                                                                             
                Queries: querys,                                                                                                                                                                                                                               
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        payload, err := proto.Marshal(request)                                                                                                                                                                                                                 
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        sig, err := signer.Sign(payload)                                                                                                                                                                                                                       
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        signedRequest := discovery.SignedRequest{                                                                                                                                                                                                              
                Payload:   payload,                                                                                                                                                                                                                            
                Signature: sig,                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        cli := discovery.NewDiscoveryClient(conn)                                                                                                                                                                                                              
                                                                                                                                                                                                                                                               
        rs, err := cli.Discover(ctx, &signedRequest)                                                                                                                                                                                          
        if err != nil {                                                                                                                                                                                                                                        
                return nil, err                                                                                                                                                                                                                                
        }                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                               
        for _, qrs := range rs.Results {                                                                                                                                                                                                                       
                return qrs.GetMembers(), nil                                                                                                                                                                                                                   
        }                                                                                                                                                                                                                                                      
        return nil, nil                                                                                                                                                                                                                                        
}

could you please open a PR with your contribution?

ok,i will do this.

from fabric-admin-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.