mirror of
https://github.com/openziti/ziti.git
synced 2026-10-13 07:41:17 +00:00
Working out how the current 'accepter' concept might be generalized for an Xlink implementation. (#54)
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019 NetFoundry, Inc.
|
||||
(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.
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
Copyright 2019 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 "github.com/netfoundry/ziti-foundation/channel2"
|
||||
|
||||
type Accepter interface {
|
||||
Accept(ch channel2.Channel) error
|
||||
}
|
||||
@@ -19,21 +19,24 @@ package xlink_transport
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/netfoundry/ziti-fabric/xlink"
|
||||
"github.com/netfoundry/ziti-foundation/channel2"
|
||||
"github.com/netfoundry/ziti-foundation/identity/identity"
|
||||
)
|
||||
|
||||
func newFactory() xlink.Factory {
|
||||
return &factory{}
|
||||
func newFactory(accepter Accepter, options *channel2.Options) xlink.Factory {
|
||||
return &factory{accepter: accepter, options: options}
|
||||
}
|
||||
|
||||
func (_ *factory) Create(id *identity.TokenId, configData map[interface{}]interface{}) (xlink.Xlink, error) {
|
||||
func (self *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
|
||||
return &impl{id: id, config: c, accepter: self.accepter, options: self.options}, nil
|
||||
}
|
||||
|
||||
type factory struct{
|
||||
id *identity.TokenId
|
||||
}
|
||||
type factory struct {
|
||||
id *identity.TokenId
|
||||
accepter Accepter
|
||||
options *channel2.Options
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/netfoundry/ziti-foundation/channel2"
|
||||
"github.com/netfoundry/ziti-foundation/identity/identity"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (self *impl) Listen() error {
|
||||
@@ -27,6 +28,7 @@ func (self *impl) Listen() error {
|
||||
if err := self.listener.Listen(); err != nil {
|
||||
return fmt.Errorf("error listening (%w)", err)
|
||||
}
|
||||
go self.runAccepter()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -38,8 +40,26 @@ func (_ *impl) GetAdvertisement() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *impl) runAccepter() {
|
||||
defer logrus.Warn("exited")
|
||||
logrus.Info("started")
|
||||
|
||||
for {
|
||||
ch, err := channel2.NewChannel("link", self.listener, self.options)
|
||||
if err == nil {
|
||||
if err := self.accepter.Accept(ch); err != nil {
|
||||
logrus.Errorf("error invoking accepter (%w)", err)
|
||||
}
|
||||
} else {
|
||||
logrus.Errorf("error accepting (%w)", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type impl struct {
|
||||
id *identity.TokenId
|
||||
config *config
|
||||
listener channel2.UnderlayListener
|
||||
accepter Accepter
|
||||
options *channel2.Options
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user