本文整理汇总了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
}