mirror of
https://github.com/hanzozt/transport.git
synced 2026-10-30 14:46:37 +00:00
61 lines
1.8 KiB
Go
61 lines
1.8 KiB
Go
/*
|
|
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 (
|
|
"github.com/openziti-incubator/cf"
|
|
"github.com/hanzozt/dilithium/protocol/westworld3"
|
|
"github.com/hanzozt/transport/v2"
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
"net"
|
|
)
|
|
|
|
func Dial(endpoint *net.UDPAddr, name string, tcfg transport.Configuration) (transport.Conn, error) {
|
|
profileId := byte(0)
|
|
if tcfg != nil {
|
|
profile := westworld3.NewBaselineProfile()
|
|
if err := profile.Load(cf.MapIToMapS(tcfg)); err != nil {
|
|
return nil, errors.Wrap(err, "load profile")
|
|
}
|
|
newProfileId, err := westworld3.AddProfile(profile)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "register profile")
|
|
}
|
|
profileId = newProfileId
|
|
}
|
|
logrus.Infof("westworld3 profile = [\n%s\n]", westworld3.GetProfile(profileId).Dump())
|
|
socket, err := westworld3.Dial(endpoint, profileId)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "dial")
|
|
}
|
|
|
|
return &Connection{
|
|
detail: &transport.ConnectionDetail{
|
|
Address: Type + ":" + endpoint.String(),
|
|
InBound: false,
|
|
Name: name,
|
|
},
|
|
Conn: socket,
|
|
}, nil
|
|
}
|
|
|
|
func DialWithLocalBinding(endpoint *net.UDPAddr, name, localBinding string, tcfg transport.Configuration) (transport.Conn, error) {
|
|
logrus.Warn("Local interface binding is not yet supported with transwarp. Dialing on the default interface")
|
|
return Dial(endpoint, name, tcfg)
|
|
}
|