diff --git a/connector/connector.go b/connector/connector.go index fd7d7261..913169e6 100644 --- a/connector/connector.go +++ b/connector/connector.go @@ -25,9 +25,16 @@ import ( "github.com/google/uuid" "github.com/rs/zerolog" + "go.mau.fi/util/dbutil" "golang.org/x/exp/slices" "google.golang.org/protobuf/proto" + "maunium.net/go/mautrix/bridgev2" + "maunium.net/go/mautrix/bridgev2/database" + "maunium.net/go/mautrix/bridgev2/networkid" + "maunium.net/go/mautrix/event" + "maunium.net/go/mautrix/id" + legacydb "go.mau.fi/mautrix-signal/database" "go.mau.fi/mautrix-signal/msgconv" "go.mau.fi/mautrix-signal/msgconv/matrixfmt" @@ -38,21 +45,20 @@ import ( signalpb "go.mau.fi/mautrix-signal/pkg/signalmeow/protobuf" "go.mau.fi/mautrix-signal/pkg/signalmeow/store" "go.mau.fi/mautrix-signal/pkg/signalmeow/types" - "maunium.net/go/mautrix/bridgev2" - "maunium.net/go/mautrix/bridgev2/database" - "maunium.net/go/mautrix/bridgev2/networkid" - "maunium.net/go/mautrix/event" - "maunium.net/go/mautrix/id" ) type SignalConnector struct { - MsgConv *msgconv.MessageConverter - DB *database.Database - SignalStore *store.Container - Bridge *bridgev2.Bridge + MsgConv *msgconv.MessageConverter + Store *store.Container + Bridge *bridgev2.Bridge +} + +func NewConnector() *SignalConnector { + return &SignalConnector{} } func (s *SignalConnector) Init(bridge *bridgev2.Bridge) { + s.Store = store.NewStore(bridge.DB.Database, dbutil.ZeroLogger(bridge.Log.With().Str("db_section", "signalmeow").Logger())) s.Bridge = bridge s.MsgConv = &msgconv.MessageConverter{ PortalMethods: &msgconvPortalMethods{}, @@ -102,6 +108,10 @@ func (s *SignalConnector) Init(bridge *bridgev2.Bridge) { } } +func (s *SignalConnector) Start(ctx context.Context) error { + return s.Store.Upgrade(ctx) +} + var _ bridgev2.NetworkConnector = (*SignalConnector)(nil) var _ bridgev2.NetworkAPI = (*SignalClient)(nil) var _ msgconv.PortalMethods = (*msgconvPortalMethods)(nil) @@ -115,7 +125,7 @@ func (s *SignalConnector) PrepareLogin(ctx context.Context, login *bridgev2.User if err != nil { return fmt.Errorf("failed to parse user login ID: %w", err) } - device, err := s.SignalStore.DeviceByACI(ctx, aci) + device, err := s.Store.DeviceByACI(ctx, aci) if err != nil { return fmt.Errorf("failed to get device from store: %w", err) } else if device == nil { diff --git a/connector/mautrix-signal-v2/main.go b/connector/mautrix-signal-v2/main.go new file mode 100644 index 00000000..ccbd6907 --- /dev/null +++ b/connector/mautrix-signal-v2/main.go @@ -0,0 +1,41 @@ +// mautrix-signal - A Matrix-Signal puppeting bridge. +// Copyright (C) 2024 Tulir Asokan +// +// 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 . + +package main + +import ( + "os" + + "go.mau.fi/util/dbutil" + "go.mau.fi/util/exerrors" + "gopkg.in/yaml.v3" + + "maunium.net/go/mautrix/bridgev2" + "maunium.net/go/mautrix/bridgev2/bridgeconfig" + "maunium.net/go/mautrix/bridgev2/matrix" + + "go.mau.fi/mautrix-signal/connector" +) + +func main() { + var cfg bridgeconfig.Config + config := exerrors.Must(os.ReadFile("config.yaml")) + exerrors.PanicIfNotNil(yaml.Unmarshal(config, &cfg)) + log := exerrors.Must(cfg.Logging.Compile()) + db := exerrors.Must(dbutil.NewFromConfig("mautrix-signal", cfg.Database, nil)) + bridge := bridgev2.NewBridge("", db, *log, matrix.NewConnector(&cfg), connector.NewConnector()) + bridge.Start() +} diff --git a/connector/mautrix-signal-v2/start b/connector/mautrix-signal-v2/start new file mode 100755 index 00000000..85c97d10 --- /dev/null +++ b/connector/mautrix-signal-v2/start @@ -0,0 +1,6 @@ +#!/bin/bash +export LIBRARY_PATH=$(dirname $(dirname $(pwd))):$LIBRARY_PATH +export MAUTRIX_VERSION=$(cat ../../go.mod | grep 'maunium.net/go/mautrix ' | head -n1 | awk '{ print $2 }') +go install -ldflags "-X main.Tag=$(git describe --exact-match --tags 2>/dev/null) -X main.Commit=$(git rev-parse HEAD) -X 'main.BuildTime=`date '+%b %_d %Y, %H:%M:%S'`' -X 'maunium.net/go/mautrix.GoModVersion=$MAUTRIX_VERSION'" || exit 2 +mkdir -p logs +mautrix-signal-v2 "$@" diff --git a/go.mod b/go.mod index fce64a70..94a4097f 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,8 @@ require ( golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 golang.org/x/net v0.24.0 google.golang.org/protobuf v1.33.0 - maunium.net/go/mautrix v0.18.2-0.20240509095639-c18758a143e2 + gopkg.in/yaml.v3 v3.0.1 + maunium.net/go/mautrix v0.18.2-0.20240509140545-7b3d8c8e82e6 nhooyr.io/websocket v1.8.11 ) @@ -45,7 +46,6 @@ require ( go.mau.fi/zeroconfig v0.1.2 // indirect golang.org/x/sys v0.19.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect maunium.net/go/mauflag v1.0.0 // indirect ) diff --git a/go.sum b/go.sum index b884ac9a..c2195fff 100644 --- a/go.sum +++ b/go.sum @@ -95,7 +95,7 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M= maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA= -maunium.net/go/mautrix v0.18.2-0.20240509095639-c18758a143e2 h1:BbaCuWiwK5mFwwt6Hmapff6jMDlQEoaKjFt1K6PPDNE= -maunium.net/go/mautrix v0.18.2-0.20240509095639-c18758a143e2/go.mod h1:r3vg2vlvbT6nyB8GdSPgYb9C6HKo3ZW3OBEoOsTdK18= +maunium.net/go/mautrix v0.18.2-0.20240509140545-7b3d8c8e82e6 h1:jczVU6x9boQfVRzV+hfWlYpx9g1OE9FCBn3+pFmlWzo= +maunium.net/go/mautrix v0.18.2-0.20240509140545-7b3d8c8e82e6/go.mod h1:r3vg2vlvbT6nyB8GdSPgYb9C6HKo3ZW3OBEoOsTdK18= nhooyr.io/websocket v1.8.11 h1:f/qXNc2/3DpoSZkHt1DQu6rj4zGC8JmkkLkWss0MgN0= nhooyr.io/websocket v1.8.11/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c=