mirror of
https://github.com/openziti/ziti.git
synced 2026-09-11 13:29:03 +00:00
Add support for multiple endpoints to services and sync model abstrac… (#53)
* Add support for multiple terminators to services and sync model abstractions with edge * Add Snapshot to db.Db * Make API friendly errors * Add association querying. Consolidate Entity* interfaces
This commit is contained in:
@@ -51,7 +51,7 @@ func (ctrlAccepter *CtrlAccepter) Run() {
|
||||
for {
|
||||
ch, err := channel2.NewChannel("ctrl", ctrlAccepter.listener, ctrlAccepter.options)
|
||||
if err == nil {
|
||||
if r, err := ctrlAccepter.network.KnownRouter(ch.Id().Token); err == nil {
|
||||
if r, err := ctrlAccepter.network.GetRouter(ch.Id().Token); err == nil {
|
||||
if ch.Underlay().Headers() != nil {
|
||||
if listenerValue, found := ch.Underlay().Headers()[channel2.HelloListenerHeader]; found {
|
||||
listenerString := string(listenerValue)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019 NetFoundry, Inc.
|
||||
Copyright 2020 NetFoundry, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,8 @@ func newBindHandler(router *network.Router, network *network.Network, xctrls []x
|
||||
func (bindHandler *bindHandler) BindChannel(ch channel2.Channel) error {
|
||||
ch.SetLogicalName(bindHandler.router.Id)
|
||||
ch.AddReceiveHandler(newSessionRequestHandler(bindHandler.router, bindHandler.network))
|
||||
ch.AddReceiveHandler(newHostRequestHandler(bindHandler.router, bindHandler.network))
|
||||
ch.AddReceiveHandler(newCreateTerminatorHandler(bindHandler.network, bindHandler.router))
|
||||
ch.AddReceiveHandler(newRemoveTerminatorHandler(bindHandler.network))
|
||||
ch.AddReceiveHandler(newLinkHandler(bindHandler.router, bindHandler.network))
|
||||
ch.AddReceiveHandler(newFaultHandler(bindHandler.router, bindHandler.network))
|
||||
ch.AddReceiveHandler(newMetricsHandler(bindHandler.network))
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
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 handler_ctrl
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/netfoundry/ziti-fabric/controller/network"
|
||||
"github.com/netfoundry/ziti-fabric/pb/ctrl_pb"
|
||||
"github.com/netfoundry/ziti-foundation/channel2"
|
||||
)
|
||||
|
||||
type hostRequestHandler struct {
|
||||
r *network.Router
|
||||
network *network.Network
|
||||
}
|
||||
|
||||
var successResponse = &ctrl_pb.BindResponse{Success: true}
|
||||
|
||||
func newHostRequestHandler(r *network.Router, network *network.Network) *hostRequestHandler {
|
||||
return &hostRequestHandler{r: r, network: network}
|
||||
}
|
||||
|
||||
func (h *hostRequestHandler) ContentType() int32 {
|
||||
return int32(ctrl_pb.ContentType_BindRequestType)
|
||||
}
|
||||
|
||||
func (h *hostRequestHandler) HandleReceive(msg *channel2.Message, ch channel2.Channel) {
|
||||
log := pfxlog.ContextLogger(ch.Label())
|
||||
|
||||
request := &ctrl_pb.BindRequest{}
|
||||
if err := proto.Unmarshal(msg.Body, request); err != nil {
|
||||
log.Errorf("unexpected error (%s)", err)
|
||||
return
|
||||
}
|
||||
|
||||
response := successResponse
|
||||
|
||||
var err error
|
||||
if request.BindType == ctrl_pb.BindType_Bind {
|
||||
err = h.network.BindService(h.r, request.Token, request.ServiceId, request.PeerData)
|
||||
} else if request.BindType == ctrl_pb.BindType_Unbind {
|
||||
err = h.network.UnbindService(h.r, request.Token, request.ServiceId)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("unexpected error (%s)", err)
|
||||
response = &ctrl_pb.BindResponse{Success: false, Message: err.Error()}
|
||||
}
|
||||
|
||||
if body, err := proto.Marshal(response); err == nil {
|
||||
responseMsg := channel2.NewMessage(int32(ctrl_pb.ContentType_BindResponseType), body)
|
||||
responseMsg.ReplyTo(msg)
|
||||
if err := h.r.Control.Send(responseMsg); err != nil {
|
||||
log.Errorf("unable to respond (%s)", err)
|
||||
}
|
||||
} else {
|
||||
log.Errorf("unexpected error (%s)", err)
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func (h *ConnectHandler) HandleConnection(hello *channel2.Hello, certificates []
|
||||
return errors.New("router already connected")
|
||||
}
|
||||
|
||||
if r, err := h.network.KnownRouter(id); err == nil {
|
||||
if r, err := h.network.GetRouter(id); err == nil {
|
||||
if r.Fingerprint != fingerprint {
|
||||
return errors.New("unenrolled router")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright 2020 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 handler_ctrl
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/netfoundry/ziti-fabric/controller/handler_common"
|
||||
"github.com/netfoundry/ziti-fabric/controller/models"
|
||||
"github.com/netfoundry/ziti-fabric/controller/network"
|
||||
"github.com/netfoundry/ziti-fabric/pb/ctrl_pb"
|
||||
"github.com/netfoundry/ziti-foundation/channel2"
|
||||
)
|
||||
|
||||
type createTerminatorHandler struct {
|
||||
router *network.Router
|
||||
network *network.Network
|
||||
}
|
||||
|
||||
func newCreateTerminatorHandler(network *network.Network, router *network.Router) *createTerminatorHandler {
|
||||
return &createTerminatorHandler{
|
||||
network: network,
|
||||
router: router,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *createTerminatorHandler) ContentType() int32 {
|
||||
return int32(ctrl_pb.ContentType_CreateTerminatorRequestType)
|
||||
}
|
||||
|
||||
func (h *createTerminatorHandler) HandleReceive(msg *channel2.Message, ch channel2.Channel) {
|
||||
request := &ctrl_pb.CreateTerminatorRequest{}
|
||||
if err := proto.Unmarshal(msg.Body, request); err != nil {
|
||||
handler_common.SendFailure(msg, ch, err.Error())
|
||||
return
|
||||
}
|
||||
terminator := &network.Terminator{
|
||||
BaseEntity: models.BaseEntity{
|
||||
Id: request.Id,
|
||||
},
|
||||
Service: request.ServiceId,
|
||||
Router: h.router.Id,
|
||||
Binding: request.Binding,
|
||||
Address: request.Address,
|
||||
PeerData: request.PeerData,
|
||||
}
|
||||
|
||||
if id, err := h.network.Terminators.Create(terminator); err == nil {
|
||||
handler_common.SendSuccess(msg, ch, id)
|
||||
} else {
|
||||
handler_common.SendFailure(msg, ch, err.Error())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright 2020 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 handler_ctrl
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/netfoundry/ziti-fabric/controller/handler_common"
|
||||
"github.com/netfoundry/ziti-fabric/controller/network"
|
||||
"github.com/netfoundry/ziti-fabric/pb/ctrl_pb"
|
||||
"github.com/netfoundry/ziti-foundation/channel2"
|
||||
)
|
||||
|
||||
type removeTerminatorHandler struct {
|
||||
network *network.Network
|
||||
}
|
||||
|
||||
func newRemoveTerminatorHandler(network *network.Network) *removeTerminatorHandler {
|
||||
return &removeTerminatorHandler{network: network}
|
||||
}
|
||||
|
||||
func (h *removeTerminatorHandler) ContentType() int32 {
|
||||
return int32(ctrl_pb.ContentType_RemoveTerminatorRequestType)
|
||||
}
|
||||
|
||||
func (h *removeTerminatorHandler) HandleReceive(msg *channel2.Message, ch channel2.Channel) {
|
||||
log := pfxlog.ContextLogger(ch.Label())
|
||||
|
||||
request := &ctrl_pb.RemoveTerminatorRequest{}
|
||||
if err := proto.Unmarshal(msg.Body, request); err != nil {
|
||||
handler_common.SendFailure(msg, ch, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
_, err := h.network.Terminators.Read(request.TerminatorId)
|
||||
if err != nil {
|
||||
handler_common.SendFailure(msg, ch, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.network.Terminators.Delete(request.TerminatorId); err == nil {
|
||||
log.Infof("removed terminator [e/%s]", request.TerminatorId)
|
||||
handler_common.SendSuccess(msg, ch, "")
|
||||
} else {
|
||||
handler_common.SendFailure(msg, ch, err.Error())
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019 NetFoundry, Inc.
|
||||
Copyright 2020 NetFoundry, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -54,7 +54,7 @@ func (h *sessionRequestHandler) HandleReceive(msg *channel2.Message, ch channel2
|
||||
if session, err := h.network.CreateSession(h.r, id, request.ServiceId); err == nil {
|
||||
responseMsg := ctrl_msg.NewSessionSuccessMsg(session.Id.Token, session.Circuit.IngressId)
|
||||
responseMsg.ReplyTo(msg)
|
||||
for k, v := range session.Service.PeerData {
|
||||
for k, v := range session.Terminator.PeerData {
|
||||
responseMsg.Headers[int32(k)] = v
|
||||
}
|
||||
if startXgressSession, err := h.r.Control.SendAndWaitWithTimeout(responseMsg, time.Second*10); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user