 9bdcbe0447
			
		
	
	9bdcbe0447
	
	
	
		
			
			Major integrations and fixes: - Added BACKBEAT SDK integration for P2P operation timing - Implemented beat-aware status tracking for distributed operations - Added Docker secrets support for secure license management - Resolved KACHING license validation via HTTPS/TLS - Updated docker-compose configuration for clean stack deployment - Disabled rollback policies to prevent deployment failures - Added license credential storage (CHORUS-DEV-MULTI-001) Technical improvements: - BACKBEAT P2P operation tracking with phase management - Enhanced configuration system with file-based secrets - Improved error handling for license validation - Clean separation of KACHING and CHORUS deployment stacks 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package kbucket
 | |
| 
 | |
| import (
 | |
| 	"container/list"
 | |
| 	"sort"
 | |
| 
 | |
| 	"github.com/libp2p/go-libp2p/core/peer"
 | |
| )
 | |
| 
 | |
| // A helper struct to sort peers by their distance to the local node
 | |
| type peerDistance struct {
 | |
| 	p        peer.ID
 | |
| 	distance ID
 | |
| }
 | |
| 
 | |
| // peerDistanceSorter implements sort.Interface to sort peers by xor distance
 | |
| type peerDistanceSorter struct {
 | |
| 	peers  []peerDistance
 | |
| 	target ID
 | |
| }
 | |
| 
 | |
| func (pds *peerDistanceSorter) Len() int { return len(pds.peers) }
 | |
| func (pds *peerDistanceSorter) Swap(a, b int) {
 | |
| 	pds.peers[a], pds.peers[b] = pds.peers[b], pds.peers[a]
 | |
| }
 | |
| func (pds *peerDistanceSorter) Less(a, b int) bool {
 | |
| 	return pds.peers[a].distance.less(pds.peers[b].distance)
 | |
| }
 | |
| 
 | |
| // Append the peer.ID to the sorter's slice. It may no longer be sorted.
 | |
| func (pds *peerDistanceSorter) appendPeer(p peer.ID, pDhtId ID) {
 | |
| 	pds.peers = append(pds.peers, peerDistance{
 | |
| 		p:        p,
 | |
| 		distance: xor(pds.target, pDhtId),
 | |
| 	})
 | |
| }
 | |
| 
 | |
| // Append the peer.ID values in the list to the sorter's slice. It may no longer be sorted.
 | |
| func (pds *peerDistanceSorter) appendPeersFromList(l *list.List) {
 | |
| 	for e := l.Front(); e != nil; e = e.Next() {
 | |
| 		pds.appendPeer(e.Value.(*PeerInfo).Id, e.Value.(*PeerInfo).dhtId)
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (pds *peerDistanceSorter) sort() {
 | |
| 	sort.Sort(pds)
 | |
| }
 | |
| 
 | |
| // SortClosestPeers Sort the given peers by their ascending distance from the target. A new slice is returned.
 | |
| func SortClosestPeers(peers []peer.ID, target ID) []peer.ID {
 | |
| 	sorter := peerDistanceSorter{
 | |
| 		peers:  make([]peerDistance, 0, len(peers)),
 | |
| 		target: target,
 | |
| 	}
 | |
| 	for _, p := range peers {
 | |
| 		sorter.appendPeer(p, ConvertPeerID(p))
 | |
| 	}
 | |
| 	sorter.sort()
 | |
| 	out := make([]peer.ID, 0, sorter.Len())
 | |
| 	for _, p := range sorter.peers {
 | |
| 		out = append(out, p.p)
 | |
| 	}
 | |
| 	return out
 | |
| }
 |