Working out how the current 'accepter' concept might be generalized for an Xlink implementation. (#54)

This commit is contained in:
Michael Quigley
2020-03-18 14:04:43 -04:00
parent 2106bc8d59
commit f953a6ce01
4 changed files with 54 additions and 8 deletions
+1 -1
View File
@@ -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.
+23
View File
@@ -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
}
+10 -7
View File
@@ -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
View File
@@ -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
}