github.com/aergoio/aergo@v1.3.1/types/peerstate.go (about) 1 package types 2 3 import "sync/atomic" 4 5 // PeerState indicated current state of peer, but 6 type PeerState int32 7 8 // indicating status of remote peer 9 const ( 10 // STARTING means connection is just estabished. 11 STARTING PeerState = iota 12 // HANDSHAKING means that local host sent status message but not receive status message from remote 13 HANDSHAKING 14 // RUNNING means complete handshake (i.e. exchanged status message) and can communicate each other 15 RUNNING 16 // STOPPING means peer was received stop signal and working in termination process. No new message is sent and receiving message is ignored. 17 STOPPING 18 // STOPPED means peer was tatally finished. 19 STOPPED 20 // DOWN means server can't communicate to remote peer. peer will be delete after TTL or 21 DOWN 22 ) 23 24 // Get returns current state with concurrent manner 25 func (s *PeerState) Get() PeerState { 26 return PeerState(atomic.LoadInt32((*int32)(s))) 27 } 28 29 // SetAndGet change state in atomic manner 30 func (s *PeerState) SetAndGet(ns PeerState) PeerState { 31 32 return PeerState(atomic.SwapInt32((*int32)(s), int32(ns))) 33 } 34 35 //go:generate stringer -type=PeerState