github.com/openziti/transport@v0.1.5/transwarp/dialer.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 transwarp
    18  
    19  import (
    20  	"github.com/openziti/dilithium/cf"
    21  	"github.com/openziti/dilithium/protocol/westworld3"
    22  	"github.com/openziti/transport"
    23  	"github.com/pkg/errors"
    24  	"github.com/sirupsen/logrus"
    25  	"net"
    26  )
    27  
    28  func Dial(endpoint *net.UDPAddr, name string, tcfg transport.Configuration) (transport.Connection, error) {
    29  	profileId := byte(0)
    30  	if tcfg != nil {
    31  		profile := westworld3.NewBaselineProfile()
    32  		if err := profile.Load(cf.MapIToMapS(tcfg)); err != nil {
    33  			return nil, errors.Wrap(err, "load profile")
    34  		}
    35  		newProfileId, err := westworld3.AddProfile(profile)
    36  		if err != nil {
    37  			return nil, errors.Wrap(err, "register profile")
    38  		}
    39  		profileId = newProfileId
    40  	}
    41  	logrus.Infof("westworld3 profile = [\n%s\n]", westworld3.GetProfile(profileId).Dump())
    42  	socket, err := westworld3.Dial(endpoint, profileId)
    43  	if err != nil {
    44  		return nil, errors.Wrap(err, "dial")
    45  	}
    46  
    47  	return &Connection{
    48  		detail: &transport.ConnectionDetail{
    49  			Address: "transwarp:" + endpoint.String(),
    50  			InBound: false,
    51  			Name:    name,
    52  		},
    53  		socket: socket,
    54  	}, nil
    55  }
    56  
    57  func DialWithLocalBinding(endpoint *net.UDPAddr, name, localBinding string, tcfg transport.Configuration) (transport.Connection, error) {
    58  	logrus.Warn("Local interface binding is not yet supported with transwarp. Dialing on the default interface")
    59  	return Dial(endpoint, name, tcfg)
    60  }