github.com/aergoio/aergo@v1.3.1/p2p/p2putil/peerutil.go (about)

     1  /*
     2   * @file
     3   * @copyright defined in aergo/LICENSE.txt
     4   */
     5  
     6  package p2putil
     7  
     8  import (
     9  	"fmt"
    10  	"github.com/aergoio/aergo/p2p/p2pcommon"
    11  	"github.com/aergoio/aergo/types"
    12  )
    13  
    14  var (
    15  	UseFullID bool
    16  )
    17  
    18  // ShortForm returns shorthanded types.PeerID.
    19  func ShortForm(pid types.PeerID) string {
    20  	pretty := pid.Pretty()
    21  	if UseFullID {
    22  		return pretty
    23  	}
    24  	if len(pretty) > 10 {
    25  		return fmt.Sprintf("%s*%s", pretty[:2], pretty[len(pretty)-6:])
    26  	} else {
    27  		return pretty
    28  	}
    29  
    30  }
    31  
    32  func ShortMetaForm(m p2pcommon.PeerMeta) string {
    33  	return fmt.Sprintf("%s:%d/%s", m.IPAddress, m.Port, ShortForm(m.ID))
    34  }