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

Commit

Permalink
Xlink progress. (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Mar 18, 2020
1 parent 0e0e627 commit e19c0ac
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 3 deletions.
7 changes: 4 additions & 3 deletions xlink/xlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
60 changes: 60 additions & 0 deletions xlink_transport/config.go
Original file line number Diff line number Diff line change
@@ -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
}
39 changes: 39 additions & 0 deletions xlink_transport/factory.go
Original file line number Diff line number Diff line change
@@ -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
}
45 changes: 45 additions & 0 deletions xlink_transport/xlink.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e19c0ac

Please sign in to comment.