當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Peer.ID方法代碼示例

本文整理匯總了Golang中github.com/disorganizer/brig/id.Peer.ID方法的典型用法代碼示例。如果您正苦於以下問題:Golang Peer.ID方法的具體用法?Golang Peer.ID怎麽用?Golang Peer.ID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/disorganizer/brig/id.Peer的用法示例。


在下文中一共展示了Peer.ID方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Open

// Open loads an existing store at `brigPath/$ID/index.bolt`, if it does not
// exist, it is created.  For full function, Connect() should be called
// afterwards.
func Open(brigPath string, owner id.Peer, IPFS *ipfsutil.Node) (*Store, error) {
	dbDir := filepath.Join(
		brigPath,
		"bolt."+strings.Replace(string(owner.ID()), "/", "-", -1),
	)

	kv, err := NewBoltKV(dbDir)
	if err != nil {
		return nil, err
	}

	fs := NewFilesystem(kv)

	st := &Store{
		repoPath: brigPath,
		IPFS:     IPFS,
		fs:       fs,
		kv:       kv,
	}

	// This version does not attempt any version checking:
	if err := fs.MetadataPut("version", []byte("1")); err != nil {
		return nil, err
	}

	if err := st.setStoreOwner(owner); err != nil {
		return nil, err
	}

	return st, err
}
開發者ID:disorganizer,項目名稱:brig,代碼行數:34,代碼來源:index.go

示例2: LastSeen

// LastSeen returns the time when we've last seen `peer`
func (cp *conversationPool) LastSeen(peer id.Peer) time.Time {
	cp.mu.Lock()
	defer cp.mu.Unlock()

	if pinger := cp.heartbeat[peer.ID()]; pinger != nil {
		return pinger.LastSeen()
	}

	return time.Unix(0, 0)
}
開發者ID:disorganizer,項目名稱:brig,代碼行數:11,代碼來源:connector.go

示例3: setStoreOwner

func (st *Store) setStoreOwner(owner id.Peer) error {
	if err := st.fs.MetadataPut("id", []byte(owner.ID())); err != nil {
		return err
	}

	if err := st.fs.MetadataPut("hash", []byte(owner.Hash())); err != nil {
		return err
	}

	return nil
}
開發者ID:disorganizer,項目名稱:brig,代碼行數:11,代碼來源:index.go

示例4: Forget

// Forget removes a peer from the pool and cleans up after it.
func (cp *conversationPool) Forget(peer id.Peer) error {
	cp.mu.Lock()
	defer cp.mu.Unlock()

	peerID := peer.ID()
	cnv, ok := cp.open[peerID]
	if !ok {
		return repo.ErrNoSuchRemote(peerID)
	}

	if pinger, ok := cp.heartbeat[peerID]; ok {
		pinger.Close()
	}

	delete(cp.open, peerID)
	delete(cp.heartbeat, peerID)
	return cnv.Close()
}
開發者ID:disorganizer,項目名稱:brig,代碼行數:19,代碼來源:connector.go

示例5: Dial

// Dial returns an APIClient that is connected to `peer`.
// If there's already a conversation to that peer no new
// connection will be created.
//
// It will return ErrOffline if the connector is not connected.
//
// Note: All connections will be multiplexed over ipfs' swarm.
func (cn *Connector) Dial(peer id.Peer) (*APIClient, error) {
	if !cn.IsInOnlineMode() {
		return nil, ErrOffline
	}

	// Check if we're allowed to connect to that node:
	if _, err := cn.rp.Remotes.Get(peer.ID()); err != nil {
		return nil, err
	}

	cnv, err := cn.layer.Dial(peer)
	if err != nil {
		return nil, err
	}

	if err := cn.cp.Remember(peer, cnv); err != nil {
		return nil, err
	}

	return newAPIClient(cnv, cn.rp.IPFS)
}
開發者ID:disorganizer,項目名稱:brig,代碼行數:28,代碼來源:connector.go

示例6: rememberUnlocked

func (cp *conversationPool) rememberUnlocked(peer id.Peer, cnv Conversation) error {
	cp.open[peer.ID()] = cnv

	// Create a new pinger if not already done:
	if _, ok := cp.heartbeat[peer.ID()]; !ok {
		pinger, err := cp.rp.IPFS.Ping(peer.Hash())
		if err != nil {
			return err
		}
		cp.heartbeat[peer.ID()] = pinger
	}

	return nil
}
開發者ID:disorganizer,項目名稱:brig,代碼行數:14,代碼來源:connector.go

示例7: NewRemoteFromPeer

func NewRemoteFromPeer(peer id.Peer) Remote {
	return NewRemote(peer.ID(), peer.Hash())
}
開發者ID:disorganizer,項目名稱:brig,代碼行數:3,代碼來源:remotes.go


注:本文中的github.com/disorganizer/brig/id.Peer.ID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。