1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00
2021-03-22 16:50:08 +01:00

25 lines
475 B
Go

package gobgp
import (
// Standard imports
"crypto/sha1"
"fmt"
"io"
// External imports
api "github.com/osrg/gobgp/api"
// Internal imports
)
func PeerHash(peer *api.Peer) string {
return PeerHashWithASAndAddress(peer.State.PeerAs, peer.State.NeighborAddress)
}
func PeerHashWithASAndAddress(asn uint32, address string) string {
h := sha1.New()
io.WriteString(h, string(asn))
io.WriteString(h, address)
sum := h.Sum(nil)
return fmt.Sprintf("%x", sum[0:5])
}