Skip to content

Commit

Permalink
Make connecting via rooms possible (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
boreq committed Oct 15, 2022
1 parent f5a13e5 commit 7c4e32c
Show file tree
Hide file tree
Showing 73 changed files with 2,540 additions and 257 deletions.
2 changes: 2 additions & 0 deletions di/inject_adapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/planetary-social/scuttlego/service/domain/identity"
"github.com/planetary-social/scuttlego/service/domain/replication"
"github.com/planetary-social/scuttlego/service/domain/replication/ebt"
"github.com/planetary-social/scuttlego/service/domain/transport/boxstream"
"go.etcd.io/bbolt"
)

Expand Down Expand Up @@ -98,6 +99,7 @@ func newFilesystemStorage(logger logging.Logger, config Config) (*blobs.Filesyst
var adaptersSet = wire.NewSet(
adapters.NewCurrentTimeProvider,
wire.Bind(new(commands.CurrentTimeProvider), new(*adapters.CurrentTimeProvider)),
wire.Bind(new(boxstream.CurrentTimeProvider), new(*adapters.CurrentTimeProvider)),

adapters.NewBanListHasher,
wire.Bind(new(bolt.BanListHasher), new(*adapters.BanListHasher)),
Expand Down
4 changes: 4 additions & 0 deletions di/inject_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/planetary-social/scuttlego/service/app/commands"
"github.com/planetary-social/scuttlego/service/app/queries"
"github.com/planetary-social/scuttlego/service/domain/replication"
"github.com/planetary-social/scuttlego/service/ports/pubsub"
portsrpc "github.com/planetary-social/scuttlego/service/ports/rpc"
)

Expand Down Expand Up @@ -45,6 +46,9 @@ var commandsSet = wire.NewSet(

commands.NewRoomsAliasRegisterHandler,
commands.NewRoomsAliasRevokeHandler,

commands.NewProcessRoomAttendantEventHandler,
wire.Bind(new(pubsub.ProcessRoomAttendantEventHandler), new(*commands.ProcessRoomAttendantEventHandler)),
)

var queriesSet = wire.NewSet(
Expand Down
31 changes: 31 additions & 0 deletions di/inject_networking.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package di

import (
"github.com/google/wire"
"github.com/planetary-social/scuttlego/service/app/commands"
"github.com/planetary-social/scuttlego/service/app/queries"
"github.com/planetary-social/scuttlego/service/domain"
"github.com/planetary-social/scuttlego/service/domain/network"
"github.com/planetary-social/scuttlego/service/domain/rooms/tunnel"
domaintransport "github.com/planetary-social/scuttlego/service/domain/transport"
"github.com/planetary-social/scuttlego/service/domain/transport/boxstream"
"github.com/planetary-social/scuttlego/service/domain/transport/rpc"
portsnetwork "github.com/planetary-social/scuttlego/service/ports/network"
)

//nolint:unused
var networkingSet = wire.NewSet(
domaintransport.NewPeerInitializer,
wire.Bind(new(portsnetwork.ServerPeerInitializer), new(*domaintransport.PeerInitializer)),
wire.Bind(new(network.ClientPeerInitializer), new(*domaintransport.PeerInitializer)),
wire.Bind(new(tunnel.ClientPeerInitializer), new(*domaintransport.PeerInitializer)),

rpc.NewConnectionIdGenerator,

boxstream.NewHandshaker,

network.NewDialer,
wire.Bind(new(commands.Dialer), new(*network.Dialer)),
wire.Bind(new(queries.Dialer), new(*network.Dialer)),
wire.Bind(new(domain.Dialer), new(*network.Dialer)),
)
2 changes: 2 additions & 0 deletions di/inject_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var portsSet = wire.NewSet(

portspubsub.NewRequestSubscriber,

portspubsub.NewRoomAttendantEventSubscriber,

local.NewDiscoverer,
portsnetwork.NewDiscoverer,
portsnetwork.NewConnectionEstablisher,
Expand Down
7 changes: 7 additions & 0 deletions di/inject_pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/planetary-social/scuttlego/service/adapters/pubsub"
"github.com/planetary-social/scuttlego/service/app/queries"
blobReplication "github.com/planetary-social/scuttlego/service/domain/blobs/replication"
"github.com/planetary-social/scuttlego/service/domain/rooms"
"github.com/planetary-social/scuttlego/service/domain/transport/rpc"
)

Expand All @@ -13,6 +14,7 @@ var pubSubSet = wire.NewSet(
requestPubSubSet,
messagePubSubSet,
blobDownloadedPubSubSet,
roomAttendantEventPubSubSet,
)

var requestPubSubSet = wire.NewSet(
Expand All @@ -30,3 +32,8 @@ var blobDownloadedPubSubSet = wire.NewSet(
wire.Bind(new(queries.BlobDownloadedSubscriber), new(*pubsub.BlobDownloadedPubSub)),
wire.Bind(new(blobReplication.BlobDownloadedPublisher), new(*pubsub.BlobDownloadedPubSub)),
)

var roomAttendantEventPubSubSet = wire.NewSet(
pubsub.NewRoomAttendantEventPubSub,
wire.Bind(new(rooms.AttendantEventPublisher), new(*pubsub.RoomAttendantEventPubSub)),
)
36 changes: 22 additions & 14 deletions di/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import (
type Service struct {
App app.Application

listener *networkport.Listener
discoverer *networkport.Discoverer
connectionEstablisher *networkport.ConnectionEstablisher
requestSubscriber *pubsubport.RequestSubscriber
advertiser *local.Advertiser
messageBuffer *commands.MessageBuffer
createHistoryStreamHandler *queries.CreateHistoryStreamHandler
listener *networkport.Listener
discoverer *networkport.Discoverer
connectionEstablisher *networkport.ConnectionEstablisher
requestSubscriber *pubsubport.RequestSubscriber
roomAttendantEventSubscriber *pubsubport.RoomAttendantEventSubscriber
advertiser *local.Advertiser
messageBuffer *commands.MessageBuffer
createHistoryStreamHandler *queries.CreateHistoryStreamHandler
}

func NewService(
Expand All @@ -31,20 +32,22 @@ func NewService(
discoverer *networkport.Discoverer,
connectionEstablisher *networkport.ConnectionEstablisher,
requestSubscriber *pubsubport.RequestSubscriber,
roomAttendantEventSubscriber *pubsubport.RoomAttendantEventSubscriber,
advertiser *local.Advertiser,
messageBuffer *commands.MessageBuffer,
createHistoryStreamHandler *queries.CreateHistoryStreamHandler,
) Service {
return Service{
App: app,

listener: listener,
discoverer: discoverer,
connectionEstablisher: connectionEstablisher,
requestSubscriber: requestSubscriber,
advertiser: advertiser,
messageBuffer: messageBuffer,
createHistoryStreamHandler: createHistoryStreamHandler,
listener: listener,
discoverer: discoverer,
connectionEstablisher: connectionEstablisher,
requestSubscriber: requestSubscriber,
roomAttendantEventSubscriber: roomAttendantEventSubscriber,
advertiser: advertiser,
messageBuffer: messageBuffer,
createHistoryStreamHandler: createHistoryStreamHandler,
}
}

Expand All @@ -65,6 +68,11 @@ func (s Service) Run(ctx context.Context) error {
errCh <- s.requestSubscriber.Run(ctx)
}()

runners++
go func() {
errCh <- s.roomAttendantEventSubscriber.Run(ctx)
}()

runners++
go func() {
errCh <- s.advertiser.Run(ctx)
Expand Down
56 changes: 28 additions & 28 deletions di/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ import (
"github.com/planetary-social/scuttlego/service/domain/feeds/formats"
"github.com/planetary-social/scuttlego/service/domain/graph"
"github.com/planetary-social/scuttlego/service/domain/identity"
"github.com/planetary-social/scuttlego/service/domain/network"
domainmocks "github.com/planetary-social/scuttlego/service/domain/mocks"
"github.com/planetary-social/scuttlego/service/domain/network/local"
"github.com/planetary-social/scuttlego/service/domain/replication"
"github.com/planetary-social/scuttlego/service/domain/replication/ebt"
"github.com/planetary-social/scuttlego/service/domain/replication/gossip"
domaintransport "github.com/planetary-social/scuttlego/service/domain/transport"
"github.com/planetary-social/scuttlego/service/domain/transport/boxstream"
"github.com/planetary-social/scuttlego/service/domain/transport/rpc"
portsnetwork "github.com/planetary-social/scuttlego/service/ports/network"
"github.com/planetary-social/scuttlego/service/domain/rooms"
"github.com/planetary-social/scuttlego/service/domain/rooms/tunnel"
"go.etcd.io/bbolt"
)

Expand Down Expand Up @@ -95,10 +93,12 @@ func BuildTestAdapters(*bbolt.DB) (TestAdapters, error) {
}

type TestCommands struct {
RoomsAliasRegister *commands.RoomsAliasRegisterHandler
RoomsAliasRevoke *commands.RoomsAliasRevokeHandler
RoomsAliasRegister *commands.RoomsAliasRegisterHandler
RoomsAliasRevoke *commands.RoomsAliasRevokeHandler
ProcessRoomAttendantEvent *commands.ProcessRoomAttendantEventHandler

Dialer *mocks.DialerMock
PeerManager *domainmocks.PeerManagerMock
Dialer *mocks.DialerMock
}

func BuildTestCommands(*testing.T) (TestCommands, error) {
Expand All @@ -108,6 +108,9 @@ func BuildTestCommands(*testing.T) (TestCommands, error) {
mocks.NewDialerMock,
wire.Bind(new(commands.Dialer), new(*mocks.DialerMock)),

domainmocks.NewPeerManagerMock,
wire.Bind(new(commands.PeerManager), new(*domainmocks.PeerManagerMock)),

identity.NewPrivate,

wire.Struct(new(TestCommands), "*"),
Expand All @@ -122,7 +125,7 @@ type TestQueries struct {
FeedRepository *mocks.FeedRepositoryMock
MessagePubSub *mocks.MessagePubSubMock
MessageRepository *mocks.MessageRepositoryMock
PeerManager *mocks.PeerManagerMock
PeerManager *domainmocks.PeerManagerMock
BlobStorage *mocks.BlobStorageMock
ReceiveLogRepository *mocks.ReceiveLogRepositoryMock
Dialer *mocks.DialerMock
Expand All @@ -139,8 +142,8 @@ func BuildTestQueries(*testing.T) (TestQueries, error) {
mocks.NewMessagePubSubMock,
wire.Bind(new(queries.MessageSubscriber), new(*mocks.MessagePubSubMock)),

mocks.NewPeerManagerMock,
wire.Bind(new(queries.PeerManager), new(*mocks.PeerManagerMock)),
domainmocks.NewPeerManagerMock,
wire.Bind(new(queries.PeerManager), new(*domainmocks.PeerManagerMock)),

identity.NewPrivate,
privateIdentityToPublicIdentity,
Expand Down Expand Up @@ -197,21 +200,6 @@ func BuildService(context.Context, identity.Private, Config) (Service, error) {
wire.Build(
NewService,

extractFromConfigSet,

boxstream.NewHandshaker,

domaintransport.NewPeerInitializer,
wire.Bind(new(portsnetwork.ServerPeerInitializer), new(*domaintransport.PeerInitializer)),
wire.Bind(new(network.ClientPeerInitializer), new(*domaintransport.PeerInitializer)),

rpc.NewConnectionIdGenerator,

network.NewDialer,
wire.Bind(new(commands.Dialer), new(*network.Dialer)),
wire.Bind(new(queries.Dialer), new(*network.Dialer)),
wire.Bind(new(domain.Dialer), new(*network.Dialer)),

domain.NewPeerManager,
wire.Bind(new(commands.NewPeerHandler), new(*domain.PeerManager)),
wire.Bind(new(commands.PeerManager), new(*domain.PeerManager)),
Expand All @@ -221,11 +209,23 @@ func BuildService(context.Context, identity.Private, Config) (Service, error) {
wire.Bind(new(commands.TransactionProvider), new(*bolt.TransactionProvider)),
newAdaptersFactory,

newBolt,

newAdvertiser,
privateIdentityToPublicIdentity,

commands.NewMessageBuffer,

rooms.NewScanner,
wire.Bind(new(domain.RoomScanner), new(*rooms.Scanner)),

rooms.NewPeerRPCAdapter,
wire.Bind(new(rooms.MetadataGetter), new(*rooms.PeerRPCAdapter)),
wire.Bind(new(rooms.AttendantsGetter), new(*rooms.PeerRPCAdapter)),

tunnel.NewDialer,
wire.Bind(new(domain.RoomDialer), new(*tunnel.Dialer)),

portsSet,
applicationSet,
replicatorSet,
Expand All @@ -235,8 +235,8 @@ func BuildService(context.Context, identity.Private, Config) (Service, error) {
boltAdaptersSet,
blobsAdaptersSet,
adaptersSet,

newBolt,
extractFromConfigSet,
networkingSet,
)
return Service{}, nil
}
Expand Down
Loading

0 comments on commit 7c4e32c

Please sign in to comment.