forked from ortuman/jackal
/
transport.go
74 lines (57 loc) · 1.64 KB
/
transport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright (c) 2018 Miguel Ángel Ortuño.
* See the LICENSE file for more information.
*/
package transport
import (
"crypto/tls"
"crypto/x509"
"io"
"github.com/ortuman/jackal/transport/compress"
)
// TransportType represents a stream transport type (socket).
type TransportType int
const (
// Socket represents a socket transport type.
Socket TransportType = iota + 1
// WebSocket represents a websocket transport type.
WebSocket
)
// String returns TransportType string representation.
func (tt TransportType) String() string {
switch tt {
case Socket:
return "socket"
case WebSocket:
return "websocket"
}
return ""
}
// ChannelBindingMechanism represents a scram channel binding mechanism.
type ChannelBindingMechanism int
const (
// TLSUnique represents 'tls-unique' channel binding mechanism.
TLSUnique ChannelBindingMechanism = iota
)
// Transport represents a stream transport mechanism.
type Transport interface {
io.ReadWriteCloser
// Type returns transport type value.
Type() TransportType
// WriteString writes a raw string to the transport.
WriteString(s string) (n int, err error)
// StartTLS secures the transport using SSL/TLS
StartTLS(cfg *tls.Config, asClient bool)
// EnableCompression activates a compression
// mechanism on the transport.
EnableCompression(compress.Level)
// ChannelBindingBytes returns current transport
// channel binding bytes.
ChannelBindingBytes(ChannelBindingMechanism) []byte
// PeerCertificates returns the certificate chain
// presented by remote peer.
PeerCertificates() []*x509.Certificate
}
type tlsStateQueryable interface {
ConnectionState() tls.ConnectionState
}