mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 15:51:21 +00:00
Xlink progress. (#54)
This commit is contained in:
+4
-3
@@ -16,13 +16,14 @@
|
||||
|
||||
package xlink
|
||||
|
||||
import "github.com/netfoundry/ziti-foundation/identity/identity"
|
||||
|
||||
type Factory interface {
|
||||
Create(config map[interface{}]interface{}) (Xlink, error)
|
||||
Create(id *identity.TokenId, config map[interface{}]interface{}) (Xlink, error)
|
||||
}
|
||||
|
||||
type Xlink interface {
|
||||
StartListener() error
|
||||
StopListener() error
|
||||
Listen() error
|
||||
Dial(address string) error
|
||||
GetAdvertisement() string
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
(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 xlink_transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/netfoundry/ziti-foundation/channel2"
|
||||
"github.com/netfoundry/ziti-foundation/transport"
|
||||
)
|
||||
|
||||
func loadConfig(data map[interface{}]interface{}) (*config, error) {
|
||||
c := &config{}
|
||||
|
||||
if value, found := data["listener"]; found {
|
||||
address, err := transport.ParseAddress(value.(string))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse listener address (%w)", err)
|
||||
}
|
||||
c.listener = address
|
||||
c.advertise = address
|
||||
} else {
|
||||
return nil, fmt.Errorf("required 'listener' configuration missing")
|
||||
}
|
||||
|
||||
if value, found := data["advertise"]; found {
|
||||
address, err := transport.ParseAddress(value.(string))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot parse advertise address (%w)", err)
|
||||
}
|
||||
c.advertise = address
|
||||
}
|
||||
|
||||
if value, found := data["options"]; found {
|
||||
if submap, ok := value.(map[interface{}]interface{}); ok {
|
||||
c.options = channel2.LoadOptions(submap)
|
||||
}
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
type config struct {
|
||||
listener transport.Address
|
||||
advertise transport.Address
|
||||
options *channel2.Options
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
(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 xlink_transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/netfoundry/ziti-fabric/xlink"
|
||||
"github.com/netfoundry/ziti-foundation/identity/identity"
|
||||
)
|
||||
|
||||
func newFactory() xlink.Factory {
|
||||
return &factory{}
|
||||
}
|
||||
|
||||
func (_ *factory) Create(id *identity.TokenId, configData map[interface{}]interface{}) (xlink.Xlink, error) {
|
||||
c, err := loadConfig(configData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error loading configuration (%w)", err)
|
||||
}
|
||||
return &impl{id: id, config: c}, nil
|
||||
}
|
||||
|
||||
type factory struct{
|
||||
id *identity.TokenId
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
(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 xlink_transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/netfoundry/ziti-foundation/channel2"
|
||||
"github.com/netfoundry/ziti-foundation/identity/identity"
|
||||
)
|
||||
|
||||
func (self *impl) Listen() error {
|
||||
self.listener = channel2.NewClassicListener(self.id, self.config.listener)
|
||||
if err := self.listener.Listen(); err != nil {
|
||||
return fmt.Errorf("error listening (%w)", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_ *impl) Dial(address string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_ *impl) GetAdvertisement() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
type impl struct {
|
||||
id *identity.TokenId
|
||||
config *config
|
||||
listener channel2.UnderlayListener
|
||||
}
|
||||
Reference in New Issue
Block a user