当前位置: 首页>>代码示例>>Golang>>正文


Golang Node.AddPeer方法代码示例

本文整理汇总了Golang中github.com/jddixon/xlNode_go.Node.AddPeer方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.AddPeer方法的具体用法?Golang Node.AddPeer怎么用?Golang Node.AddPeer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/jddixon/xlNode_go.Node的用法示例。


在下文中一共展示了Node.AddPeer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewMemberMaker

// Given contact information for a registry and the name of a cluster,
// the client joins the cluster, collects information on the other members,
// and terminates when it has info on the entire membership.
func NewMemberMaker(
	node *xn.Node, attrs uint64,
	regName string, regID *xi.NodeID, regEnd xt.EndPointI,
	regCK, regSK *rsa.PublicKey,
	clusterName string, clusterAttrs uint64, clusterID *xi.NodeID,
	size, epCount uint32, endPoints []xt.EndPointI) (
	mm *MemberMaker, err error) {

	var (
		cm      *xcl.ClusterMember
		isAdmin = (attrs & xcl.ATTR_ADMIN) != 0
		regPeer *xn.Peer
	)
	// sanity checks on parameter list
	if node == nil {
		err = MissingNode
	} else {
		if regName == "" || regID == nil || regEnd == nil ||
			regCK == nil {

			err = MissingServerInfo
		}
		if err == nil {
			// DEBUG
			fmt.Printf("NemMemberMaker: regEnd is %s\n", regEnd.String())
			// END
			if (attrs & xcl.ATTR_SOLO) == uint64(0) {
				if clusterName == "" {
					err = MissingClusterNameOrID
					if err == nil && size < uint32(1) {
						// err = ClusterMustHaveTwo
						err = ClusterMustHaveMember
					}
				}
				if err == nil {
					// if the client is an admin client epCount applies
					// to the cluster
					if epCount < uint32(1) {
						epCount = uint32(1)
					}
					if !isAdmin {
						// XXX There is some confusion here: we don't require
						// that all members have the same number of endpoints
						actualEPCount := uint32(len(endPoints))
						if actualEPCount == 0 {
							err = MemberMustHaveEndPoint
						} else if epCount > actualEPCount {
							epCount = actualEPCount
						}
						for i := 0; i < int(epCount); i++ {
							_, err = node.AddEndPoint(endPoints[i])
						}
					}
				}
			}
		}
	}

	if err == nil {
		var ctor xt.ConnectorI
		var ctors []xt.ConnectorI
		ctor, err = xt.NewTcpConnector(regEnd)
		if err == nil {
			ctors = append(ctors, ctor)
			regPeer, err = xn.NewPeer(regName, regID, regCK, regSK,
				nil, ctors)
			if err == nil {
				_, err = node.AddPeer(regPeer)
			}
		}
	}
	if err == nil {
		cm = &xcl.ClusterMember{
			// Attrs gets negotiated
			ClusterName:    clusterName,
			ClusterAttrs:   clusterAttrs,
			ClusterID:      clusterID,
			ClusterMaxSize: size,
			EPCount:        epCount,
			// Members added on the fly
			Members: make([]*xcl.MemberInfo, size),
			Node:    *node,
		}
		mm = &MemberMaker{
			ProposedAttrs: attrs,
			DoneCh:        make(chan error, 1),
			RegPeer:       regPeer,
			ClusterMember: *cm,
		}
	}
	return
}
开发者ID:jddixon,项目名称:xlReg_go,代码行数:95,代码来源:memberNode.go


注:本文中的github.com/jddixon/xlNode_go.Node.AddPeer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。