• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang xlNodeID_go.NodeID类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/jddixon/xlNodeID_go.NodeID的典型用法代码示例。如果您正苦于以下问题:Golang NodeID类的具体用法?Golang NodeID怎么用?Golang NodeID使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: NewRegCluster

func NewRegCluster(name string, id *xi.NodeID, attrs uint64,
	maxSize, epCount uint32) (rc *RegCluster, err error) {

	var m ha.HAMT

	if name == "" {
		name = "xlCluster"
	}
	nameMap := make(map[string]*ClientInfo)
	if epCount < 1 {
		err = ClusterMembersMustHaveEndPoint
	}
	if err == nil && maxSize < 1 {
		//err = ClusterMustHaveTwo
		err = ClusterMustHaveMember
	} else {
		t := uint(xm.NextExp2_32(maxSize))
		m, err = ha.NewHAMT(DEFAULT_W, t)
	}
	if err == nil {
		rc = &RegCluster{
			Attrs:         attrs,
			Name:          name,
			ID:            id.Value(),
			epCount:       epCount,
			maxSize:       maxSize,
			MembersByName: nameMap,
			MembersByID:   m,
		}
	}
	return
}
开发者ID:jddixon,项目名称:xlReg_go,代码行数:32,代码来源:reg_cluster.go


示例2: ContainsID

func (reg *Registry) ContainsID(n *xi.NodeID) (found bool, err error) {
	found, _, err = reg.idFilter.IsMember(n.Value())

	// DEBUG
	reg.Logger.Printf("Registry.ContainsID(%x) returning %v, %v\n",
		n.Value(), found, err)
	// END
	return
}
开发者ID:jddixon,项目名称:xlReg_go,代码行数:9,代码来源:registry.go


示例3: Add

// Add a file to the collection.  This operation must be idempotent.
func (mc *MemCache) Add(id *xi.NodeID, b []byte) (err error) {

	key := id.Value()

	// XXX POSSIBLE DEADLOCK
	mc.mu.Lock()
	defer mc.mu.Unlock()

	value, err := mc.idMap.Find(key)
	if err == nil {
		if value == nil {
			mc.idMap.Insert(key, b)
			mc.itemCount++
			mc.byteCount += uint64(len(b))
		}
	}
	return
}
开发者ID:jddixon,项目名称:xlOverlay_go,代码行数:19,代码来源:memCache.go


示例4: InsertID

func (reg *Registry) InsertID(n *xi.NodeID) (err error) {
	b := n.Value()
	// DEBUG
	reg.Logger.Printf("Registry.InsertID(%x)\n", b)
	// END
	found, _, err := reg.idFilter.IsMember(b)
	if err == nil {
		if found {
			// DEBUG
			reg.Logger.Printf("  id is already registered\n")
			// END
			err = IDAlreadyInUse
		} else {
			err = reg.idFilter.Insert(b)
			// DEBUG
			reg.Logger.Printf("  added %x to registry; err is %v\n", b, err)
			// END
		}
	}
	return
}
开发者ID:jddixon,项目名称:xlReg_go,代码行数:21,代码来源:registry.go


示例5: NewChunk

// Datum is declared a NodeID to restrict its value to certain byteslice
// lengths.
func NewChunk(datum *xi.NodeID, ndx uint32, data []byte) (
	ch *Chunk, err error) {

	if datum == nil {
		err = NilDatum
	} else if data == nil {
		err = NilData
	} else if len(data) == 0 {
		err = ZeroLengthChunk
	} else if len(data) > MAX_CHUNK_BYTES {
		err = ChunkTooLong
	} else {
		msgHash := datum.Value()
		realLen := len(data)
		adjLen := ((realLen + WORD_BYTES - 1) / WORD_BYTES) * WORD_BYTES
		paddingBytes := adjLen - realLen
		packet := make([]byte, DATUM_OFFSET)
		datumPadding := make([]byte, DATUM_PADDING)
		ch = &Chunk{packet: packet}
		ch.setLength(uint32(realLen)) // length of the data part
		ch.setIndex(ndx)              // index of this chunk in overall message
		ch.packet = append(ch.packet, msgHash...)
		ch.packet = append(ch.packet, datumPadding...)
		ch.packet = append(ch.packet, data...)
		if paddingBytes > 0 {
			padding := make([]byte, paddingBytes)
			ch.packet = append(ch.packet, padding...)
		}
		// calculate the SHA1 hash of the chunk
		d := sha1.New()
		d.Write(ch.packet)
		chunkHash := d.Sum(nil)

		// append that to the packet
		ch.packet = append(ch.packet, chunkHash...)
	}
	return
}
开发者ID:jddixon,项目名称:xlProtocol_go,代码行数:40,代码来源:chunk.go


示例6: doClientMsg

func doClientMsg(h *InHandler) {
	var err error
	defer func() {
		h.errOut = err
	}()

	// DEBUG
	regName := h.reg.GetName()
	h.reg.Logger.Printf("doClientMsg: regName is %s\n", regName)
	// END

	// Examine incoming message -------------------------------------
	var (
		name   string
		attrs  uint64
		nodeID *xi.NodeID
		ck, sk *rsa.PublicKey
		myEnds []string
		hash   []byte
		cm     *ClientInfo
	)

	// XXX We should accept EITHER clientName + token OR clientID
	// This implementation only accepts a token.

	clientMsg := h.msgIn
	clientSpecs := clientMsg.GetMemberSpecs()
	name = clientSpecs.GetName()
	attrs = clientSpecs.GetAttrs()
	ckBytes := clientSpecs.GetCommsKey()
	skBytes := clientSpecs.GetSigKey()
	digSig := clientSpecs.GetDigSig()

	ck, err = xc.RSAPubKeyFromWire(ckBytes)
	if err == nil {
		sk, err = xc.RSAPubKeyFromWire(skBytes)
		if err == nil {
			myEnds = clientSpecs.GetMyEnds() // a string array
		}
	}
	if err == nil {
		// calculate hash over fields in canonical order XXX EXCLUDING ID
		aBytes := make([]byte, 8)
		binary.LittleEndian.PutUint64(aBytes, attrs)
		d := sha1.New()
		d.Write([]byte(name))
		d.Write(aBytes)
		d.Write(ckBytes)
		d.Write(skBytes)
		for i := 0; i < len(myEnds); i++ {
			d.Write([]byte(myEnds[i]))
		}
		hash = d.Sum(nil)
		// verify the digital signature
		err = rsa.VerifyPKCS1v15(sk, crypto.SHA1, hash, digSig)
	}
	if err == nil {
		id := clientSpecs.GetID()
		// DEBUG
		if id == nil {
			h.reg.Logger.Println("  doClientMsg: id from Specs is NIL")
		} else {
			h.reg.Logger.Printf("  doClientMsg: id from Specs is %x\n", id)
		}
		// END
		if id == nil {
			nodeID, err = h.reg.InsertUniqueNodeID()
			// DEBUG
			h.reg.Logger.Printf("  doClientMsg: inserting %x returned %v\n", id, err)
			// END
			if err == nil {
				id := nodeID.Value()
				// this is echoed to the console
				h.reg.Logger.Printf("doClientMsg: assigning new MemberID %xi, user %s",
					id, name)
			}
		} else {
			// must be known to the registry
			nodeID, err = xi.New(id)
			if err == nil {
				var found bool
				found, err = h.reg.ContainsID(nodeID)
				if err == nil && !found {
					err = h.reg.InsertID(nodeID)
				}
			}
		}
	}
	// Take appropriate action --------------------------------------
	if err == nil || err == IDAlreadyInUse {
		// The appropriate action is to hang a token for this client off
		// the InHandler.
		cm, err = NewClientInfo(name, nodeID, ck, sk, attrs, myEnds)
		if err == nil {
			h.thisClient = cm
		}
	}
	if err == nil {
		// Prepare reply to client --------------------------------------
		// In this implementation We simply accept the client's proposed
//.........这里部分代码省略.........
开发者ID:jddixon,项目名称:xlReg_go,代码行数:101,代码来源:msg_handlers.go


示例7: doCreateMsg

func doCreateMsg(h *InHandler) {
	var err error
	defer func() {
		h.errOut = err
	}()
	// Examine incoming message -------------------------------------
	var (
		clusterID *xi.NodeID
		index     int
	)

	createMsg := h.msgIn
	clusterName := createMsg.GetClusterName()
	clusterAttrs := createMsg.GetClusterAttrs()
	clusterMaxSize := createMsg.GetClusterMaxSize()
	endPointCount := createMsg.GetEndPointCount()

	// Take appropriate action --------------------------------------

	// Determine whether the cluster exists.  If it does, we will just
	// use its existing properties.

	h.reg.mu.RLock()
	cluster, exists := h.reg.ClustersByName[clusterName]
	h.reg.mu.RUnlock()

	if exists {
		h.reg.Logger.Printf("doCreateMsg: cluster %s already exists\n", clusterName)
		clusterMaxSize = cluster.maxSize
		clusterAttrs = cluster.Attrs
		endPointCount = cluster.epCount
		if cluster.ID == nil {
			h.reg.Logger.Println("  no ID for cluster %s\n", clusterName)
			clusterID, _ = xi.New(nil)
		} else {
			clusterID, _ = xi.New(cluster.ID)
		}
		// XXX index not assigned
	} else {
		h.reg.Logger.Printf("doCreateMsg: new cluster %s\n", clusterName)
		attrs := uint64(0)
		if clusterMaxSize < MIN_CLUSTER_SIZE {
			clusterMaxSize = MIN_CLUSTER_SIZE
		} else if clusterMaxSize > MAX_CLUSTER_SIZE {
			clusterMaxSize = MAX_CLUSTER_SIZE
		}
		// Assign a quasi-random cluster ID, adding it to the registry
		clusterID, err = h.reg.InsertUniqueNodeID()
		if err == nil {
			cluster, err = NewRegCluster(clusterName, clusterID, attrs,
				clusterMaxSize, endPointCount)
			h.reg.Logger.Printf("cluster %s assigning ID %x\n",
				clusterName, clusterID.Value())
		}
		if err == nil {
			h.cluster = cluster
			index, err = h.reg.AddCluster(cluster)
			// XXX index not used
		}
	}
	_ = index // INDEX IS NOT BEING USED

	if err == nil {
		// Prepare reply to client --------------------------------------
		op := XLRegMsg_CreateReply
		id := clusterID.Value()
		h.msgOut = &XLRegMsg{
			Op:             &op,
			ClusterID:      id,
			ClusterMaxSize: &clusterMaxSize,
			ClusterAttrs:   &clusterAttrs,
			EndPointCount:  &endPointCount,
		}
		// Set exit state -----------------------------------------------
		h.exitState = CREATE_REQUEST_RCVD
	}
}
开发者ID:jddixon,项目名称:xlReg_go,代码行数:77,代码来源:msg_handlers.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang lfs.PathExists函数代码示例发布时间:2022-05-23
下一篇:
Golang xlNode_go.Node类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap