Hyperledger Fabric Source Analysis peer service startup process

Source: Internet
Author: User
Tags hyperledger fabric

Peer service is the primary service.

The service supports a variety of peer commands.

Includes query status, start, Stop node service, and so on.

The startup process is in Peer/main.go. Serve function

The most important is the Func serve (args []string) error function.

When the peer node Start command is executed, a node service is started.

The first is the configuration management, based on the configuration information and some calculations to build the cache structure, probe node information and so on.

The main call Core.peer package to implement.

    If err: = Peer. Cacheconfiguration (); Err! = Nil {
        return err
    }

    peerendpoint, err: = Peer. Getpeerendpoint ()
    if err! = Nil {
        err = fmt. Errorf ("Failed to get Peer Endpoint:%s", err)
        return err
    }

After that, start the GRPC service and listen to Port 7051.

    LISTENADDR: = Viper. GetString ("peer.listenaddress")

    if "" = = listenaddr {
        logger. Debug ("Listen address not specified, using peer endpoint address")
        listenaddr = peerendpoint.address
    }

    Lis, ERR: = Net. Listen ("TCP", LISTENADDR)

Create the Eventhub service, implemented by calling the Createeventhubserver () method, which is also GRPC, and only the VP node is turned on.

LIS, err = net. Listen ("TCP", Viper. GetString ("peer.validator.events.address")) if err! = Nil {return nil, nil, FMT.
    Errorf ("Failed to listen:%v", err)}//todo-do We need different SSL material for events? var opts []grpc. Serveroption if Comm. Tlsenabled () {creds, err: = credentials. Newservertlsfromfile (Viper. GetString ("Peer.tls.cert.file"), Viper. GetString ("Peer.tls.key.file")) if err! = Nil {return nil, nil, FMT. Errorf ("Failed to generate credentials%v", err)} opts = []grpc. Serveroption{grpc. Creds (creds)}} grpcserver = Grpc.
    NewServer (opts ...) Ehserver: = producer. Neweventsserver (UINT (Viper). GetInt ("Peer.validator.events.buffersize")), Viper. GetInt ("Peer.validator.events.timeout")) PB. Registereventsserver (Grpcserver, Ehserver)

Start the database service.

    Db. Start ()

Start a GRPC service.

Grpcserver: = Grpc. NewServer (opts ...)

Register for Chaincode Support services.

    Sechelper, err: = Getsechelper ()
    if err! = Nil {
        return err
    }

    sechelperfunc: = Func () crypto. Peer {
        return sechelper
    }

    registerchaincodesupport (Chaincode. Defaultchain, Grpcserver, Sechelper)

Create the Peer node service, and note the VP and NVP nodes.

    If peer. Validatorenabled () {
        logger. Debug ("Running as validating peer-making Genesis block if needed")
        makegenesiserror: = Genesis. Makegenesis ()
        if makegenesiserror! = nil {
            return makegenesiserror
        }
        logger. DEBUGF ("Running as validating peer-installing consensus%s", Viper. GetString ("Peer.validator.consensus"))
        peerserver, err = Peer. Newpeerwithengine (Sechelperfunc, Helper.) Getengine)
    } else {
        logger. Debug ("Running as non-validating peer")
        peerserver, err = Peer. Newpeerwithhandler (Sechelperfunc, Peer. Newpeerhandler)
    }

Register peer node services, management Services, DevOps Services, Openchain services, and so on, if you turn on rest, start the rest service.

 PB. Registerpeerserver (Grpcserver, Peerserver)//Register the Admin server PB. Registeradminserver (Grpcserver, Core. Newadminserver ())//Register Devops server Serverdevops: = Core. Newdevopsserver (Peerserver) PB. Registerdevopsserver (Grpcserver, Serverdevops)//Register The Serveropenchain server Serveropenchain, err: = Res T.newopenchainserverwithpeerinfo (peerserver) if err! = Nil {err = FMT. Errorf ("Error Creating Openchainserver:%s", err) return err} PB. Registeropenchainserver (Grpcserver, Serveropenchain)//Create and register the REST service if configured if VIP Er. Getbool ("rest.enabled") {go rest. Startopenchainrestserver (Serveropenchain, Serverdevops)} 

Finally, start the GRPC service side of these services and start the Eventhub server. If profiling is required, the listening service is also turned on.


For more source analysis, please refer to https://github.com/yeasy/hyperledger_code_fabric.


Reprint Please specify: http://blog.csdn.net/yeasy/article/details/52096267.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.