This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e0e627
commit e19c0ac
Showing
4 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |