From 34fb57acc0ebe006d29089ce5e92b5941d49cac0 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 24 Mar 2020 10:18:57 -0400 Subject: [PATCH] Remove transwarp transport implementation. --- transwarp/address.go | 74 ------------------------------------- transwarp/connection.go | 81 ----------------------------------------- transwarp/dialer.go | 46 ----------------------- transwarp/listener.go | 44 ---------------------- 4 files changed, 245 deletions(-) delete mode 100644 transwarp/address.go delete mode 100644 transwarp/connection.go delete mode 100644 transwarp/dialer.go delete mode 100644 transwarp/listener.go diff --git a/transwarp/address.go b/transwarp/address.go deleted file mode 100644 index b4191db60..000000000 --- a/transwarp/address.go +++ /dev/null @@ -1,74 +0,0 @@ -/* - (c) Copyright NetFoundry, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package transwarp - -import ( - "fmt" - "github.com/netfoundry/ziti-foundation/identity/identity" - "github.com/netfoundry/ziti-foundation/transport" - "io" - "strconv" - "strings" -) - -func (self address) Dial(name string, _ *identity.TokenId) (transport.Connection, error) { - return Dial(self.bindableAddress(), name) -} - -func (self address) Listen(name string, _ *identity.TokenId, incoming chan transport.Connection) (io.Closer, error) { - return Listen(self.bindableAddress(), name, incoming) -} - -func (self address) MustListen(name string, _ *identity.TokenId, incoming chan transport.Connection) io.Closer { - closer, err := self.Listen(name, nil, incoming) - if err != nil { - panic(fmt.Errorf("cannot listen (%w)", err)) - } - return closer -} - -func (self address) String() string { - return fmt.Sprintf("transwarp:%s", self.bindableAddress()) -} - -func (self address) bindableAddress() string { - return fmt.Sprintf("%s:%d", self.hostname, self.port) -} - -type address struct { - hostname string - port uint16 -} - -type AddressParser struct{} - -func (_ AddressParser) Parse(s string) (transport.Address, error) { - tokens := strings.Split(s, ":") - if len(tokens) != 3 { - return nil, fmt.Errorf("invalid format") - } - - if tokens[0] == "transwarp" { - port, err := strconv.ParseUint(tokens[2], 10, 16) - if err != nil { - return nil, err - } - return &address{hostname: tokens[1], port: uint16(port)}, nil - } - - return nil, fmt.Errorf("invalid format") -} diff --git a/transwarp/connection.go b/transwarp/connection.go deleted file mode 100644 index 942074b0a..000000000 --- a/transwarp/connection.go +++ /dev/null @@ -1,81 +0,0 @@ -/* - (c) Copyright NetFoundry, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package transwarp - -import ( - "crypto/x509" - "github.com/netfoundry/ziti-foundation/transport" - "io" - "net" - "time" -) - -func (self *connection) Detail() *transport.ConnectionDetail { - return self.detail -} - -func (_ *connection) PeerCertificates() []*x509.Certificate { - return nil -} - -func (self *connection) Reader() io.Reader { - return self.socket -} - -func (self *connection) ReadPeer(p []byte) (int, transport.Address, error) { - n, peer, err := self.socket.ReadFromUDP(p) - var addr transport.Address - if peer != nil { - addr = &address{hostname: peer.IP.String(), port: uint16(peer.Port)} - } - return n, addr, err -} - -func (self *connection) Writer() io.Writer { - return self.socket -} - -func (self *connection) Conn() net.Conn { - return self.socket -} - -func (self *connection) SetReadTimeout(t time.Duration) error { - return self.socket.SetReadDeadline(time.Now().Add(t)) -} - -func (self *connection) SetWriteTimeout(t time.Duration) error { - return self.socket.SetWriteDeadline(time.Now().Add(t)) -} - -func (self *connection) Close() error { - return self.socket.Close() -} - -func newConnection(detail *transport.ConnectionDetail, socket *net.UDPConn) *connection { - return &connection{ - detail: detail, - socket: socket, - buffer: make([]byte, 4096), - } -} - -type connection struct { - detail *transport.ConnectionDetail - socket *net.UDPConn - buffer []byte - copy []byte -} diff --git a/transwarp/dialer.go b/transwarp/dialer.go deleted file mode 100644 index 8a82df4ce..000000000 --- a/transwarp/dialer.go +++ /dev/null @@ -1,46 +0,0 @@ -/* - (c) Copyright NetFoundry, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package transwarp - -import ( - "fmt" - "github.com/netfoundry/ziti-foundation/transport" - "net" -) - -func Dial(destination, name string) (transport.Connection, error) { - destinationAddress, err := net.ResolveUDPAddr("udp", destination) - if err != nil { - return nil, fmt.Errorf("error resolving destination address (%w)", err) - } - - localAddress, err := net.ResolveUDPAddr("udp", ":0") - if err != nil { - return nil, fmt.Errorf("error resolving local address (%w)", err) - } - - conn, err := net.DialUDP("udp", localAddress, destinationAddress) - if err != nil { - return nil, fmt.Errorf("error dialing (%w)", err) - } - - return newConnection(&transport.ConnectionDetail{ - Address: "transwarp" + destination, - InBound: false, - Name: name, - }, conn), nil -} diff --git a/transwarp/listener.go b/transwarp/listener.go deleted file mode 100644 index ffbc01f9e..000000000 --- a/transwarp/listener.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - (c) Copyright NetFoundry, Inc. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package transwarp - -import ( - "fmt" - "github.com/netfoundry/ziti-foundation/transport" - "io" - "net" -) - -func Listen(bindAddress, name string, incoming chan transport.Connection) (io.Closer, error) { - listenAddress, err := net.ResolveUDPAddr("udp", bindAddress) - if err != nil { - return nil, fmt.Errorf("error resolving bind address (%w)", err) - } - - socket, err := net.ListenUDP("udp", listenAddress) - if err != nil { - return nil, fmt.Errorf("error listening (%w)", err) - } - - incoming <- newConnection(&transport.ConnectionDetail{ - Address: "transwarp" + bindAddress, - InBound: true, - Name: name, - }, socket) - - return socket, nil -}