Better naming

This commit is contained in:
Neil Alexander 2021-08-10 15:23:13 +01:00
parent b5f5ff8ba4
commit 371d71bba8
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
17 changed files with 80 additions and 80 deletions

View file

@ -75,11 +75,11 @@ type InputReceiptEventRequest struct {
// InputReceiptEventResponse is a response to InputReceiptEventRequest
type InputReceiptEventResponse struct{}
type InputSigningKeyUpdateRequest struct {
SigningKeyUpdate `json:"signing_keys"`
type InputCrossSigningKeyUpdateRequest struct {
CrossSigningKeyUpdate `json:"signing_keys"`
}
type InputSigningKeyUpdateResponse struct{}
type InputCrossSigningKeyUpdateResponse struct{}
// EDUServerInputAPI is used to write events to the typing server.
type EDUServerInputAPI interface {
@ -101,9 +101,9 @@ type EDUServerInputAPI interface {
response *InputReceiptEventResponse,
) error
InputSigningKeyUpdate(
InputCrossSigningKeyUpdate(
ctx context.Context,
request *InputSigningKeyUpdateRequest,
response *InputSigningKeyUpdateResponse,
request *InputCrossSigningKeyUpdateRequest,
response *InputCrossSigningKeyUpdateResponse,
) error
}

View file

@ -53,5 +53,5 @@ type OutputReceiptEvent struct {
// OutputSigningKeyUpdate is an entry in the signing key update output kafka log
type OutputSigningKeyUpdate struct {
SigningKeyUpdate `json:"signing_keys"`
CrossSigningKeyUpdate `json:"signing_keys"`
}

View file

@ -40,7 +40,7 @@ type ReceiptTS struct {
TS gomatrixserverlib.Timestamp `json:"ts"`
}
type SigningKeyUpdate struct {
type CrossSigningKeyUpdate struct {
MasterKey *gomatrixserverlib.CrossSigningKey `json:"master_key,omitempty"`
SelfSigningKey *gomatrixserverlib.CrossSigningKey `json:"self_signing_key,omitempty"`
UserID string `json:"user_id"`

View file

@ -46,13 +46,13 @@ func NewInternalAPI(
_, producer := kafka.SetupConsumerProducer(&cfg.Matrix.Kafka)
return &input.EDUServerInputAPI{
Cache: eduCache,
UserAPI: userAPI,
Producer: producer,
OutputTypingEventTopic: cfg.Matrix.Kafka.TopicFor(config.TopicOutputTypingEvent),
OutputSendToDeviceEventTopic: cfg.Matrix.Kafka.TopicFor(config.TopicOutputSendToDeviceEvent),
OutputReceiptEventTopic: cfg.Matrix.Kafka.TopicFor(config.TopicOutputReceiptEvent),
OutputSigningKeyUpdateTopic: cfg.Matrix.Kafka.TopicFor(config.TopicOutputSigningKeyUpdate),
ServerName: cfg.Matrix.ServerName,
Cache: eduCache,
UserAPI: userAPI,
Producer: producer,
OutputTypingEventTopic: cfg.Matrix.Kafka.TopicFor(config.TopicOutputTypingEvent),
OutputSendToDeviceEventTopic: cfg.Matrix.Kafka.TopicFor(config.TopicOutputSendToDeviceEvent),
OutputReceiptEventTopic: cfg.Matrix.Kafka.TopicFor(config.TopicOutputReceiptEvent),
OutputCrossSigningKeyUpdateTopic: cfg.Matrix.Kafka.TopicFor(config.TopicOutputCrossSigningKeyUpdate),
ServerName: cfg.Matrix.ServerName,
}
}

View file

@ -40,7 +40,7 @@ type EDUServerInputAPI struct {
// The kafka topic to output new receipt events to
OutputReceiptEventTopic string
// The kafka topic to output new signing key changes to
OutputSigningKeyUpdateTopic string
OutputCrossSigningKeyUpdateTopic string
// kafka producer
Producer sarama.SyncProducer
// Internal user query API
@ -79,14 +79,14 @@ func (t *EDUServerInputAPI) InputSendToDeviceEvent(
return t.sendToDeviceEvent(ise)
}
// InputSigningKeyUpdate implements api.EDUServerInputAPI
func (t *EDUServerInputAPI) InputSigningKeyUpdate(
// InputCrossSigningKeyUpdate implements api.EDUServerInputAPI
func (t *EDUServerInputAPI) InputCrossSigningKeyUpdate(
ctx context.Context,
request *api.InputSigningKeyUpdateRequest,
response *api.InputSigningKeyUpdateResponse,
request *api.InputCrossSigningKeyUpdateRequest,
response *api.InputCrossSigningKeyUpdateResponse,
) error {
eventJSON, err := json.Marshal(&api.OutputSigningKeyUpdate{
SigningKeyUpdate: request.SigningKeyUpdate,
CrossSigningKeyUpdate: request.CrossSigningKeyUpdate,
})
if err != nil {
return err
@ -94,10 +94,10 @@ func (t *EDUServerInputAPI) InputSigningKeyUpdate(
logrus.WithFields(logrus.Fields{
"user_id": request.UserID,
}).Infof("Producing to topic '%s'", t.OutputSigningKeyUpdateTopic)
}).Infof("Producing to topic '%s'", t.OutputCrossSigningKeyUpdateTopic)
m := &sarama.ProducerMessage{
Topic: string(t.OutputSigningKeyUpdateTopic),
Topic: string(t.OutputCrossSigningKeyUpdateTopic),
Key: sarama.StringEncoder(request.UserID),
Value: sarama.ByteEncoder(eventJSON),
}

View file

@ -12,10 +12,10 @@ import (
// HTTP paths for the internal HTTP APIs
const (
EDUServerInputTypingEventPath = "/eduserver/input"
EDUServerInputSendToDeviceEventPath = "/eduserver/sendToDevice"
EDUServerInputReceiptEventPath = "/eduserver/receipt"
EDUServerInputSigningKeyUpdatePath = "/eduserver/signingKeyUpdate"
EDUServerInputTypingEventPath = "/eduserver/input"
EDUServerInputSendToDeviceEventPath = "/eduserver/sendToDevice"
EDUServerInputReceiptEventPath = "/eduserver/receipt"
EDUServerInputCrossSigningKeyUpdatePath = "/eduserver/crossSigningKeyUpdate"
)
// NewEDUServerClient creates a EDUServerInputAPI implemented by talking to a HTTP POST API.
@ -70,15 +70,15 @@ func (h *httpEDUServerInputAPI) InputReceiptEvent(
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
}
// InputSigningKeyUpdate implements EDUServerInputAPI
func (h *httpEDUServerInputAPI) InputSigningKeyUpdate(
// InputCrossSigningKeyUpdate implements EDUServerInputAPI
func (h *httpEDUServerInputAPI) InputCrossSigningKeyUpdate(
ctx context.Context,
request *api.InputSigningKeyUpdateRequest,
response *api.InputSigningKeyUpdateResponse,
request *api.InputCrossSigningKeyUpdateRequest,
response *api.InputCrossSigningKeyUpdateResponse,
) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "InputSigningKeyUpdate")
span, ctx := opentracing.StartSpanFromContext(ctx, "InputCrossSigningKeyUpdate")
defer span.Finish()
apiURL := h.eduServerURL + EDUServerInputSigningKeyUpdatePath
apiURL := h.eduServerURL + EDUServerInputCrossSigningKeyUpdatePath
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
}

View file

@ -51,14 +51,14 @@ func AddRoutes(t api.EDUServerInputAPI, internalAPIMux *mux.Router) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
internalAPIMux.Handle(EDUServerInputSigningKeyUpdatePath,
httputil.MakeInternalAPI("inputSigningKeyUpdate", func(req *http.Request) util.JSONResponse {
var request api.InputSigningKeyUpdateRequest
var response api.InputSigningKeyUpdateResponse
internalAPIMux.Handle(EDUServerInputCrossSigningKeyUpdatePath,
httputil.MakeInternalAPI("inputCrossSigningKeyUpdate", func(req *http.Request) util.JSONResponse {
var request api.InputCrossSigningKeyUpdateRequest
var response api.InputCrossSigningKeyUpdateResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.MessageResponse(http.StatusBadRequest, err.Error())
}
if err := t.InputSigningKeyUpdate(req.Context(), &request, &response); err != nil {
if err := t.InputCrossSigningKeyUpdate(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}

View file

@ -503,18 +503,18 @@ func (t *txnReq) processEDUs(ctx context.Context) {
}
}
case eduserverAPI.MSigningKeyUpdate:
var updatePayload eduserverAPI.SigningKeyUpdate
var updatePayload eduserverAPI.CrossSigningKeyUpdate
if err := json.Unmarshal(e.Content, &updatePayload); err != nil {
util.GetLogger(ctx).WithError(err).WithFields(logrus.Fields{
"user_id": updatePayload.UserID,
}).Error("Failed to send signing key update to edu server")
continue
}
inputReq := &eduserverAPI.InputSigningKeyUpdateRequest{
SigningKeyUpdate: updatePayload,
inputReq := &eduserverAPI.InputCrossSigningKeyUpdateRequest{
CrossSigningKeyUpdate: updatePayload,
}
inputRes := &eduserverAPI.InputSigningKeyUpdateResponse{}
if err := t.eduAPI.InputSigningKeyUpdate(ctx, inputReq, inputRes); err != nil {
inputRes := &eduserverAPI.InputCrossSigningKeyUpdateResponse{}
if err := t.eduAPI.InputCrossSigningKeyUpdate(ctx, inputReq, inputRes); err != nil {
util.GetLogger(ctx).WithError(err).Error("Failed to send signing key update to EDU server")
continue
}

View file

@ -84,10 +84,10 @@ func (o *testEDUProducer) InputReceiptEvent(
return nil
}
func (o *testEDUProducer) InputSigningKeyUpdate(
func (o *testEDUProducer) InputCrossSigningKeyUpdate(
ctx context.Context,
request *eduAPI.InputSigningKeyUpdateRequest,
response *eduAPI.InputSigningKeyUpdateResponse,
request *eduAPI.InputCrossSigningKeyUpdateRequest,
response *eduAPI.InputCrossSigningKeyUpdateResponse,
) error {
return nil
}

View file

@ -32,7 +32,7 @@ import (
log "github.com/sirupsen/logrus"
)
type OutputSigningKeyUpdateConsumer struct {
type CrossSigningKeyUpdateConsumer struct {
consumer *internal.ContinualConsumer
db storage.Database
queues *queue.OutgoingQueues
@ -40,19 +40,19 @@ type OutputSigningKeyUpdateConsumer struct {
rsAPI roomserverAPI.RoomserverInternalAPI
}
func NewOutputSigningKeyUpdateConsumer(
func NewCrossSigningKeyUpdateConsumer(
process *process.ProcessContext,
cfg *config.KeyServer,
kafkaConsumer sarama.Consumer,
queues *queue.OutgoingQueues,
store storage.Database,
rsAPI roomserverAPI.RoomserverInternalAPI,
) *OutputSigningKeyUpdateConsumer {
c := &OutputSigningKeyUpdateConsumer{
) *CrossSigningKeyUpdateConsumer {
c := &CrossSigningKeyUpdateConsumer{
consumer: &internal.ContinualConsumer{
Process: process,
ComponentName: "federationsender/signingkeys",
Topic: string(cfg.Matrix.Kafka.TopicFor(config.TopicOutputSigningKeyUpdate)),
Topic: string(cfg.Matrix.Kafka.TopicFor(config.TopicOutputCrossSigningKeyUpdate)),
Consumer: kafkaConsumer,
PartitionStore: store,
},
@ -66,14 +66,14 @@ func NewOutputSigningKeyUpdateConsumer(
return c
}
func (t *OutputSigningKeyUpdateConsumer) Start() error {
func (t *CrossSigningKeyUpdateConsumer) Start() error {
if err := t.consumer.Start(); err != nil {
return fmt.Errorf("t.consumer.Start: %w", err)
}
return nil
}
func (t *OutputSigningKeyUpdateConsumer) onMessage(msg *sarama.ConsumerMessage) error {
func (t *CrossSigningKeyUpdateConsumer) onMessage(msg *sarama.ConsumerMessage) error {
var output eduapi.OutputSigningKeyUpdate
if err := json.Unmarshal(msg.Value, &output); err != nil {
logrus.WithError(err).Errorf("eduserver output log: message parse failure")
@ -112,7 +112,7 @@ func (t *OutputSigningKeyUpdateConsumer) onMessage(msg *sarama.ConsumerMessage)
Type: eduapi.MSigningKeyUpdate,
Origin: string(t.serverName),
}
if edu.Content, err = json.Marshal(output.SigningKeyUpdate); err != nil {
if edu.Content, err = json.Marshal(output.CrossSigningKeyUpdate); err != nil {
return err
}

View file

@ -94,7 +94,7 @@ func NewInternalAPI(
if err := keyConsumer.Start(); err != nil {
logrus.WithError(err).Panic("failed to start key server consumer")
}
signingKeyConsumer := consumers.NewOutputSigningKeyUpdateConsumer(
signingKeyConsumer := consumers.NewCrossSigningKeyUpdateConsumer(
base.ProcessContext, &base.Cfg.KeyServer, consumer, queues, federationSenderDB, rsAPI,
)
if err := signingKeyConsumer.Start(); err != nil {

View file

@ -16,28 +16,28 @@ import (
"github.com/Shopify/sarama"
)
type OutputSigningKeyUpdateConsumer struct {
type OutputCrossSigningKeyUpdateConsumer struct {
eduServerConsumer *internal.ContinualConsumer
keyDB storage.Database
keyAPI api.KeyInternalAPI
serverName string
}
func NewOutputSigningKeyUpdateConsumer(
func NewOutputCrossSigningKeyUpdateConsumer(
process *process.ProcessContext,
cfg *config.Dendrite,
kafkaConsumer sarama.Consumer,
keyDB storage.Database,
keyAPI api.KeyInternalAPI,
) *OutputSigningKeyUpdateConsumer {
) *OutputCrossSigningKeyUpdateConsumer {
consumer := internal.ContinualConsumer{
Process: process,
ComponentName: "keyserver/eduserver",
Topic: cfg.Global.Kafka.TopicFor(config.TopicOutputSigningKeyUpdate),
Topic: cfg.Global.Kafka.TopicFor(config.TopicOutputCrossSigningKeyUpdate),
Consumer: kafkaConsumer,
PartitionStore: keyDB,
}
s := &OutputSigningKeyUpdateConsumer{
s := &OutputCrossSigningKeyUpdateConsumer{
eduServerConsumer: &consumer,
keyDB: keyDB,
keyAPI: keyAPI,
@ -48,11 +48,11 @@ func NewOutputSigningKeyUpdateConsumer(
return s
}
func (s *OutputSigningKeyUpdateConsumer) Start() error {
func (s *OutputCrossSigningKeyUpdateConsumer) Start() error {
return s.eduServerConsumer.Start()
}
func (s *OutputSigningKeyUpdateConsumer) onMessage(msg *sarama.ConsumerMessage) error {
func (s *OutputCrossSigningKeyUpdateConsumer) onMessage(msg *sarama.ConsumerMessage) error {
var output eduapi.OutputSigningKeyUpdate
if err := json.Unmarshal(msg.Value, &output); err != nil {
logrus.WithError(err).Errorf("eduserver output log: message parse failure")

View file

@ -226,7 +226,7 @@ func (a *KeyInternalAPI) PerformUploadDeviceKeys(ctx context.Context, req *api.P
// Finally, generate a notification that we updated the keys.
if _, host, err := gomatrixserverlib.SplitID('@', req.UserID); err == nil && host == a.ThisServer {
update := eduserverAPI.SigningKeyUpdate{
update := eduserverAPI.CrossSigningKeyUpdate{
UserID: req.UserID,
}
if _, ok := toStore[gomatrixserverlib.CrossSigningKeyPurposeMaster]; ok {

View file

@ -40,7 +40,7 @@ type KeyInternalAPI struct {
FedClient fedsenderapi.FederationClient
UserAPI userapi.UserInternalAPI
DeviceKeysProducer *producers.KeyChange
CrossSigningProducer *producers.SigningKeyUpdate
CrossSigningProducer *producers.CrossSigningKeyUpdate
Updater *DeviceListUpdater
}

View file

@ -51,8 +51,8 @@ func NewInternalAPI(
Producer: producer,
DB: db,
}
signingKeyUpdateProducer := &producers.SigningKeyUpdate{
Topic: string(cfg.Matrix.Kafka.TopicFor(config.TopicOutputSigningKeyUpdate)),
crossSigningKeyUpdateProducer := &producers.CrossSigningKeyUpdate{
Topic: string(cfg.Matrix.Kafka.TopicFor(config.TopicOutputCrossSigningKeyUpdate)),
Producer: producer,
}
ap := &internal.KeyInternalAPI{
@ -60,7 +60,7 @@ func NewInternalAPI(
ThisServer: cfg.Matrix.ServerName,
FedClient: fedClient,
DeviceKeysProducer: keyChangeProducer,
CrossSigningProducer: signingKeyUpdateProducer,
CrossSigningProducer: crossSigningKeyUpdateProducer,
}
updater := internal.NewDeviceListUpdater(db, ap, keyChangeProducer, fedClient, 8) // 8 workers TODO: configurable
ap.Updater = updater
@ -70,7 +70,7 @@ func NewInternalAPI(
}
}()
keyconsumer := consumers.NewOutputSigningKeyUpdateConsumer(
keyconsumer := consumers.NewOutputCrossSigningKeyUpdateConsumer(
base.ProcessContext, base.Cfg, consumer, db, ap,
)
if err := keyconsumer.Start(); err != nil {

View file

@ -22,19 +22,19 @@ import (
"github.com/sirupsen/logrus"
)
type SigningKeyUpdate struct {
type CrossSigningKeyUpdate struct {
Topic string
Producer sarama.SyncProducer
}
func (p *SigningKeyUpdate) DefaultPartition() int32 {
func (p *CrossSigningKeyUpdate) DefaultPartition() int32 {
return 0
}
func (p *SigningKeyUpdate) ProduceSigningKeyUpdate(key api.SigningKeyUpdate) error {
func (p *CrossSigningKeyUpdate) ProduceSigningKeyUpdate(key api.CrossSigningKeyUpdate) error {
var m sarama.ProducerMessage
output := &api.OutputSigningKeyUpdate{
SigningKeyUpdate: key,
CrossSigningKeyUpdate: key,
}
value, err := json.Marshal(output)

View file

@ -4,13 +4,13 @@ import "fmt"
// Defined Kafka topics.
const (
TopicOutputTypingEvent = "OutputTypingEvent"
TopicOutputSendToDeviceEvent = "OutputSendToDeviceEvent"
TopicOutputKeyChangeEvent = "OutputKeyChangeEvent"
TopicOutputRoomEvent = "OutputRoomEvent"
TopicOutputClientData = "OutputClientData"
TopicOutputReceiptEvent = "OutputReceiptEvent"
TopicOutputSigningKeyUpdate = "OutputSigningKeyUpdate"
TopicOutputTypingEvent = "OutputTypingEvent"
TopicOutputSendToDeviceEvent = "OutputSendToDeviceEvent"
TopicOutputKeyChangeEvent = "OutputKeyChangeEvent"
TopicOutputRoomEvent = "OutputRoomEvent"
TopicOutputClientData = "OutputClientData"
TopicOutputReceiptEvent = "OutputReceiptEvent"
TopicOutputCrossSigningKeyUpdate = "OutputCrossSigningKeyUpdate"
)
type Kafka struct {