2021-05-08 14:25:55 +02:00
|
|
|
/*
|
|
|
|
GoToSocial
|
2023-01-05 12:43:00 +01:00
|
|
|
Copyright (C) 2021-2023 GoToSocial Authors admin@gotosocial.org
|
2021-05-08 14:25:55 +02:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2021-05-30 13:12:00 +02:00
|
|
|
package processing
|
2021-05-08 14:25:55 +02:00
|
|
|
|
|
|
|
import (
|
2022-05-15 11:16:43 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
|
2021-05-08 14:25:55 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2021-10-31 15:46:23 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/email"
|
2021-05-08 14:25:55 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/federation"
|
2023-02-22 16:05:26 +01:00
|
|
|
mm "github.com/superseriousbusiness/gotosocial/internal/media"
|
2021-08-31 15:59:12 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
2021-05-08 14:25:55 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
2021-07-05 13:23:03 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/account"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/admin"
|
2023-02-22 16:05:26 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/fedi"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/media"
|
2023-01-23 13:14:21 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/report"
|
2021-07-05 13:23:03 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/status"
|
2023-02-22 16:05:26 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/stream"
|
2021-10-14 14:26:04 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/processing/user"
|
2022-07-03 12:08:30 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/storage"
|
2021-06-13 18:42:28 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/timeline"
|
2021-05-08 14:25:55 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
2021-06-17 18:02:33 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/visibility"
|
2021-05-08 14:25:55 +02:00
|
|
|
)
|
|
|
|
|
2023-02-22 16:05:26 +01:00
|
|
|
type Processor struct {
|
2022-05-15 11:16:43 +02:00
|
|
|
clientWorker *concurrency.WorkerPool[messages.FromClientAPI]
|
|
|
|
fedWorker *concurrency.WorkerPool[messages.FromFederator]
|
2022-04-28 14:23:11 +02:00
|
|
|
|
2021-06-13 18:42:28 +02:00
|
|
|
federator federation.Federator
|
|
|
|
tc typeutils.TypeConverter
|
|
|
|
oauthServer oauth.Server
|
2023-02-22 16:05:26 +01:00
|
|
|
mediaManager mm.Manager
|
2022-11-24 09:35:46 +01:00
|
|
|
storage *storage.Driver
|
2022-02-05 12:47:38 +01:00
|
|
|
statusTimelines timeline.Manager
|
2021-06-13 18:42:28 +02:00
|
|
|
db db.DB
|
2021-06-17 18:02:33 +02:00
|
|
|
filter visibility.Filter
|
2021-05-08 14:25:55 +02:00
|
|
|
|
2021-06-13 18:42:28 +02:00
|
|
|
/*
|
|
|
|
SUB-PROCESSORS
|
|
|
|
*/
|
|
|
|
|
2023-02-22 16:05:26 +01:00
|
|
|
account account.Processor
|
|
|
|
admin admin.Processor
|
|
|
|
fedi fedi.Processor
|
|
|
|
media media.Processor
|
|
|
|
report report.Processor
|
|
|
|
status status.Processor
|
|
|
|
stream stream.Processor
|
|
|
|
user user.Processor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Account() *account.Processor {
|
|
|
|
return &p.account
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Admin() *admin.Processor {
|
|
|
|
return &p.admin
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Fedi() *fedi.Processor {
|
|
|
|
return &p.fedi
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Media() *media.Processor {
|
|
|
|
return &p.media
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Report() *report.Processor {
|
|
|
|
return &p.report
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Status() *status.Processor {
|
|
|
|
return &p.status
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) Stream() *stream.Processor {
|
|
|
|
return &p.stream
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Processor) User() *user.Processor {
|
|
|
|
return &p.user
|
2021-05-08 14:25:55 +02:00
|
|
|
}
|
|
|
|
|
2021-10-31 15:46:23 +01:00
|
|
|
// NewProcessor returns a new Processor.
|
|
|
|
func NewProcessor(
|
|
|
|
tc typeutils.TypeConverter,
|
|
|
|
federator federation.Federator,
|
|
|
|
oauthServer oauth.Server,
|
2023-02-22 16:05:26 +01:00
|
|
|
mediaManager mm.Manager,
|
2022-11-24 09:35:46 +01:00
|
|
|
storage *storage.Driver,
|
2021-10-31 15:46:23 +01:00
|
|
|
db db.DB,
|
2022-04-28 14:23:11 +02:00
|
|
|
emailSender email.Sender,
|
2022-05-15 11:16:43 +02:00
|
|
|
clientWorker *concurrency.WorkerPool[messages.FromClientAPI],
|
|
|
|
fedWorker *concurrency.WorkerPool[messages.FromFederator],
|
2023-02-22 16:05:26 +01:00
|
|
|
) *Processor {
|
2022-03-29 11:54:56 +02:00
|
|
|
parseMentionFunc := GetParseMentionFunc(db, federator)
|
2021-05-08 14:25:55 +02:00
|
|
|
|
2022-02-05 12:47:38 +01:00
|
|
|
filter := visibility.NewFilter(db)
|
2021-05-08 14:25:55 +02:00
|
|
|
|
2023-02-22 16:05:26 +01:00
|
|
|
return &Processor{
|
2022-04-28 14:23:11 +02:00
|
|
|
clientWorker: clientWorker,
|
|
|
|
fedWorker: fedWorker,
|
|
|
|
|
2021-06-13 18:42:28 +02:00
|
|
|
federator: federator,
|
|
|
|
tc: tc,
|
|
|
|
oauthServer: oauthServer,
|
2021-12-28 16:36:00 +01:00
|
|
|
mediaManager: mediaManager,
|
2021-09-11 21:18:06 +02:00
|
|
|
storage: storage,
|
2022-02-05 12:47:38 +01:00
|
|
|
statusTimelines: timeline.NewManager(StatusGrabFunction(db), StatusFilterFunction(db, filter), StatusPrepareFunction(db, tc), StatusSkipInsertFunction()),
|
2021-06-13 18:42:28 +02:00
|
|
|
db: db,
|
2023-02-22 16:05:26 +01:00
|
|
|
filter: filter,
|
|
|
|
|
|
|
|
// sub processors
|
|
|
|
account: account.New(db, tc, mediaManager, oauthServer, clientWorker, federator, parseMentionFunc),
|
|
|
|
admin: admin.New(db, tc, mediaManager, federator.TransportController(), storage, clientWorker),
|
|
|
|
fedi: fedi.New(db, tc, federator),
|
|
|
|
media: media.New(db, tc, mediaManager, federator.TransportController(), storage),
|
|
|
|
report: report.New(db, tc, clientWorker),
|
|
|
|
status: status.New(db, tc, clientWorker, parseMentionFunc),
|
|
|
|
stream: stream.New(db, oauthServer),
|
|
|
|
user: user.New(db, emailSender),
|
2021-06-13 18:42:28 +02:00
|
|
|
}
|
2021-05-08 14:25:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start starts the Processor, reading from its channels and passing messages back and forth.
|
2023-02-22 16:05:26 +01:00
|
|
|
func (p *Processor) Start() error {
|
2022-04-28 14:23:11 +02:00
|
|
|
// Setup and start the client API worker pool
|
|
|
|
p.clientWorker.SetProcessor(p.ProcessFromClientAPI)
|
|
|
|
if err := p.clientWorker.Start(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup and start the federator worker pool
|
|
|
|
p.fedWorker.SetProcessor(p.ProcessFromFederator)
|
|
|
|
if err := p.fedWorker.Start(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-22 19:38:10 +01:00
|
|
|
// Start status timelines
|
|
|
|
if err := p.statusTimelines.Start(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-15 18:43:08 +02:00
|
|
|
return nil
|
2021-05-08 14:25:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop stops the processor cleanly, finishing handling any remaining messages before closing down.
|
2023-02-22 16:05:26 +01:00
|
|
|
func (p *Processor) Stop() error {
|
2022-04-28 14:23:11 +02:00
|
|
|
if err := p.clientWorker.Stop(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-22 19:38:10 +01:00
|
|
|
|
2022-04-28 14:23:11 +02:00
|
|
|
if err := p.fedWorker.Stop(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-11-22 19:38:10 +01:00
|
|
|
|
|
|
|
if err := p.statusTimelines.Stop(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-05-08 14:25:55 +02:00
|
|
|
return nil
|
|
|
|
}
|