perspective.go 501 B

1234567891011121314151617181920212223242526
  1. package protocol
  2. // Perspective determines if we're acting as a server or a client
  3. type Perspective int
  4. // the perspectives
  5. const (
  6. PerspectiveServer Perspective = 1
  7. PerspectiveClient Perspective = 2
  8. )
  9. // Opposite returns the perspective of the peer
  10. func (p Perspective) Opposite() Perspective {
  11. return 3 - p
  12. }
  13. func (p Perspective) String() string {
  14. switch p {
  15. case PerspectiveServer:
  16. return "Server"
  17. case PerspectiveClient:
  18. return "Client"
  19. default:
  20. return "invalid perspective"
  21. }
  22. }