cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
datagramsession/event.go
50lines · modecode
| 1 | package datagramsession |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "io" |
| 6 | |
| 7 | "github.com/google/uuid" |
| 8 | ) |
| 9 | |
| 10 | // registerSessionEvent is an event to start tracking a new session |
| 11 | type registerSessionEvent struct { |
| 12 | sessionID uuid.UUID |
| 13 | originProxy io.ReadWriteCloser |
| 14 | resultChan chan *Session |
| 15 | } |
| 16 | |
| 17 | func newRegisterSessionEvent(sessionID uuid.UUID, originProxy io.ReadWriteCloser) *registerSessionEvent { |
| 18 | return ®isterSessionEvent{ |
| 19 | sessionID: sessionID, |
| 20 | originProxy: originProxy, |
| 21 | resultChan: make(chan *Session, 1), |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | // unregisterSessionEvent is an event to stop tracking and terminate the session. |
| 26 | type unregisterSessionEvent struct { |
| 27 | sessionID uuid.UUID |
| 28 | err *errClosedSession |
| 29 | } |
| 30 | |
| 31 | // ClosedSessionError represent a condition that closes the session other than I/O |
| 32 | // I/O error is not included, because the side that closes the session is ambiguous. |
| 33 | type errClosedSession struct { |
| 34 | message string |
| 35 | byRemote bool |
| 36 | } |
| 37 | |
| 38 | func (sc *errClosedSession) Error() string { |
| 39 | if sc.byRemote { |
| 40 | return fmt.Sprintf("session closed by remote due to %s", sc.message) |
| 41 | } else { |
| 42 | return fmt.Sprintf("session closed by local due to %s", sc.message) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | // newDatagram is an event when transport receives new datagram |
| 47 | type newDatagram struct { |
| 48 | sessionID uuid.UUID |
| 49 | payload []byte |
| 50 | } |
| 51 | |