github.com/aergoio/aergo@v1.3.1/types/p2pmore.go (about)

     1  /**
     2   *  @file
     3   *  @copyright defined in aergo/LICENSE.txt
     4   */
     5  
     6  package types
     7  
     8  import (
     9  	"net"
    10  	"strconv"
    11  	"time"
    12  )
    13  
    14  type PeerBlockInfo interface {
    15  	ID() PeerID
    16  	State() PeerState
    17  	LastStatus() *LastBlockStatus
    18  }
    19  
    20  // LastBlockStatus i
    21  type LastBlockStatus struct {
    22  	CheckTime   time.Time
    23  	BlockHash   []byte
    24  	BlockNumber uint64
    25  }
    26  
    27  // ResponseMessage contains response status
    28  type ResponseMessage interface {
    29  	GetStatus() ResultStatus
    30  }
    31  
    32  // AddressesToStringMap make map of string for logging or json encoding
    33  func AddressesToStringMap(addrs []*PeerAddress) []map[string]string {
    34  	arr := make([]map[string]string, len(addrs))
    35  	for i, addr := range addrs {
    36  		vMap := make(map[string]string)
    37  		vMap["address"] = net.IP(addr.Address).String()
    38  		vMap["port"] = strconv.Itoa(int(addr.Port))
    39  		vMap["peerId"] = PeerID(addr.PeerID).Pretty()
    40  		arr[i] = vMap
    41  	}
    42  	return arr
    43  }