event.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package datagramsession
  2. import (
  3. "fmt"
  4. "io"
  5. "github.com/google/uuid"
  6. )
  7. // registerSessionEvent is an event to start tracking a new session
  8. type registerSessionEvent struct {
  9. sessionID uuid.UUID
  10. originProxy io.ReadWriteCloser
  11. resultChan chan *Session
  12. }
  13. func newRegisterSessionEvent(sessionID uuid.UUID, originProxy io.ReadWriteCloser) *registerSessionEvent {
  14. return &registerSessionEvent{
  15. sessionID: sessionID,
  16. originProxy: originProxy,
  17. resultChan: make(chan *Session, 1),
  18. }
  19. }
  20. // unregisterSessionEvent is an event to stop tracking and terminate the session.
  21. type unregisterSessionEvent struct {
  22. sessionID uuid.UUID
  23. err *errClosedSession
  24. }
  25. // ClosedSessionError represent a condition that closes the session other than I/O
  26. // I/O error is not included, because the side that closes the session is ambiguous.
  27. type errClosedSession struct {
  28. message string
  29. byRemote bool
  30. }
  31. func (sc *errClosedSession) Error() string {
  32. if sc.byRemote {
  33. return fmt.Sprintf("session closed by remote due to %s", sc.message)
  34. } else {
  35. return fmt.Sprintf("session closed by local due to %s", sc.message)
  36. }
  37. }