gotosocial/internal/federation/federator.go

81 lines
2.8 KiB
Go
Raw Normal View History

2021-04-28 21:46:13 +02:00
/*
GoToSocial
Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package federation
import (
"github.com/go-fed/activity/pub"
2021-04-29 17:54:28 +02:00
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
2021-05-04 17:50:00 +02:00
"github.com/superseriousbusiness/gotosocial/internal/message"
2021-04-29 17:54:28 +02:00
"github.com/superseriousbusiness/gotosocial/internal/transport"
2021-05-02 19:51:12 +02:00
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
2021-04-28 21:46:13 +02:00
)
2021-05-02 19:51:12 +02:00
// Federator wraps various interfaces and functions to manage activitypub federation from gotosocial
2021-04-28 21:46:13 +02:00
type Federator interface {
2021-05-02 19:51:12 +02:00
FederatingActor() pub.FederatingActor
TransportController() transport.Controller
FederatingProtocol() pub.FederatingProtocol
CommonBehavior() pub.CommonBehavior
2021-04-28 21:46:13 +02:00
}
type federator struct {
2021-05-02 19:51:12 +02:00
actor pub.FederatingActor
2021-05-04 17:50:00 +02:00
processor message.Processor
2021-05-02 19:51:12 +02:00
federatingProtocol pub.FederatingProtocol
commonBehavior pub.CommonBehavior
clock pub.Clock
transportController transport.Controller
2021-04-28 21:46:13 +02:00
}
2021-04-29 17:54:28 +02:00
// NewFederator returns a new federator
2021-05-04 17:50:00 +02:00
func NewFederator(db db.DB, transportController transport.Controller, config *config.Config, log *logrus.Logger, processor message.Processor, typeConverter typeutils.TypeConverter) Federator {
2021-04-29 17:54:28 +02:00
clock := &Clock{}
2021-05-02 19:51:12 +02:00
federatingProtocol := newFederatingProtocol(db, log, config, transportController, typeConverter)
2021-04-29 17:54:28 +02:00
commonBehavior := newCommonBehavior(db, log, config, transportController)
2021-05-02 19:51:12 +02:00
actor := newFederatingActor(commonBehavior, federatingProtocol, db.Federation(), clock)
2021-04-29 17:54:28 +02:00
2021-04-28 21:46:13 +02:00
return &federator{
2021-05-02 19:51:12 +02:00
actor: actor,
2021-05-04 17:50:00 +02:00
processor: processor,
2021-05-02 19:51:12 +02:00
federatingProtocol: federatingProtocol,
commonBehavior: commonBehavior,
clock: clock,
transportController: transportController,
2021-04-28 21:46:13 +02:00
}
}
2021-04-29 17:54:28 +02:00
2021-05-02 19:51:12 +02:00
func (f *federator) FederatingActor() pub.FederatingActor {
return f.actor
2021-04-29 17:54:28 +02:00
}
2021-05-02 19:51:12 +02:00
func (f *federator) TransportController() transport.Controller {
return f.transportController
2021-04-29 17:54:28 +02:00
}
2021-05-02 19:51:12 +02:00
func (f *federator) FederatingProtocol() pub.FederatingProtocol {
return f.federatingProtocol
2021-04-29 17:54:28 +02:00
}
2021-05-02 19:51:12 +02:00
func (f *federator) CommonBehavior() pub.CommonBehavior {
return f.commonBehavior
2021-04-29 17:54:28 +02:00
}