github.com/openziti/transport@v0.1.5/connection.go (about) 1 /* 2 Copyright NetFoundry, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 https://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package transport 18 19 import ( 20 "crypto/x509" 21 "io" 22 "net" 23 "time" 24 ) 25 26 type ConnectionDetail struct { 27 Address string 28 InBound bool 29 Name string 30 } 31 32 func (cd *ConnectionDetail) String() string { 33 out := "" 34 if cd.InBound { 35 out += cd.Address + " <-" 36 if len(cd.Name) > 0 { 37 out += " {" + cd.Name + "}" 38 } 39 40 } else { 41 if len(cd.Name) > 0 { 42 out += "{" + cd.Name + "} " 43 } 44 out += "-> " + cd.Address 45 } 46 return out 47 } 48 49 // Connection represents an abstract connection (ingress or egress). 50 // 51 type Connection interface { 52 Detail() *ConnectionDetail 53 PeerCertificates() []*x509.Certificate 54 Reader() io.Reader 55 Writer() io.Writer 56 Conn() net.Conn 57 SetReadTimeout(t time.Duration) error 58 ClearReadTimeout() error 59 SetWriteTimeout(t time.Duration) error 60 ClearWriteTimeout() error 61 io.Closer 62 }