Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
xlink_transport uses handler_link, just like it's spiritual predecess…
Browse files Browse the repository at this point in the history
…or. (#54)
  • Loading branch information
michaelquigley committed Mar 20, 2020
1 parent dd0ee75 commit 2b28287
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 52 deletions.
23 changes: 0 additions & 23 deletions router/xlink_transport/accepter.go

This file was deleted.

27 changes: 21 additions & 6 deletions router/xlink_transport/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,40 @@ package xlink_transport

import (
"fmt"
forwarder2 "github.com/netfoundry/ziti-fabric/router/forwarder"
"github.com/netfoundry/ziti-fabric/router/xgress"
"github.com/netfoundry/ziti-fabric/router/xlink"
"github.com/netfoundry/ziti-foundation/channel2"
"github.com/netfoundry/ziti-foundation/identity/identity"
)

func newFactory(accepter Accepter, options *channel2.Options) xlink.Factory {
return &factory{accepter: accepter, options: options}
func NewFactory(ctrl xgress.CtrlChannel, forwarder *forwarder2.Forwarder, forwarderOptions *forwarder2.Options, options *channel2.Options) xlink.Factory {
return &factory{
ctrl: ctrl,
forwarder: forwarder,
forwarderOptions: forwarderOptions,
options: options,
}
}

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, accepter: self.accepter, options: self.options}, nil
return &impl{
id: id,
config: c,
ctrl: self.ctrl,
forwarder: self.forwarder,
forwarderOptions: self.forwarderOptions,
options: self.options,
}, nil
}

type factory struct {
id *identity.TokenId
accepter Accepter
options *channel2.Options
ctrl xgress.CtrlChannel
forwarder *forwarder2.Forwarder
forwarderOptions *forwarder2.Options
options *channel2.Options
}
34 changes: 11 additions & 23 deletions router/xlink_transport/xlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ package xlink_transport

import (
"fmt"
"github.com/netfoundry/ziti-fabric/router/forwarder"
"github.com/netfoundry/ziti-fabric/router/handler_link"
"github.com/netfoundry/ziti-fabric/router/xgress"
"github.com/netfoundry/ziti-foundation/channel2"
"github.com/netfoundry/ziti-foundation/identity/identity"
"github.com/sirupsen/logrus"
)

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)
}
go self.runAccepter()
go handler_link.NewAccepter(self.id, self.ctrl, self.forwarder, self.listener, self.options, self.forwarderOptions)
return nil
}

Expand All @@ -40,26 +42,12 @@ 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
id *identity.TokenId
config *config
listener channel2.UnderlayListener
ctrl xgress.CtrlChannel
forwarder *forwarder.Forwarder
forwarderOptions *forwarder.Options
options *channel2.Options
}

0 comments on commit 2b28287

Please sign in to comment.