Skip to content

Commit af96ea2

Browse files
committed
refactor: add MountedLink to bind transport to link
Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent dd1d035 commit af96ea2

26 files changed

+309
-792
lines changed

link/establish-link-ex.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ func EstablishLinkWithPeerEx(
1515
b bus.Bus,
1616
localPeerID, remotePeerID peer.ID,
1717
returnIfIdle bool,
18-
) (Link, func(), error) {
18+
) (EstablishLinkWithPeerValue, func(), error) {
1919
estl, _, ref, err := bus.ExecWaitValue[EstablishLinkWithPeerValue](
2020
ctx,
2121
b,
22-
NewEstablishLinkWithPeer(
23-
localPeerID, remotePeerID,
24-
),
22+
NewEstablishLinkWithPeer(localPeerID, remotePeerID),
2523
bus.ReturnIfIdle(returnIfIdle),
2624
nil,
2725
nil,

link/establish-link.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type EstablishLinkWithPeer interface {
2727
}
2828

2929
// EstablishLinkWithPeerValue is the type emitted when resolving EstablishLinkWithPeer.
30-
type EstablishLinkWithPeerValue = Link
30+
type EstablishLinkWithPeerValue = MountedLink
3131

3232
// establishLinkWithPeer implements EstablishLinkWithPeer with a peer ID constraint.
3333
type establishLinkWithPeer struct {

link/mounted-link.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package link
2+
3+
import (
4+
"context"
5+
6+
"github.com/aperturerobotics/bifrost/peer"
7+
"github.com/aperturerobotics/bifrost/protocol"
8+
"github.com/aperturerobotics/bifrost/stream"
9+
)
10+
11+
// MountedLink is a Link managed by the transport controller.
12+
type MountedLink interface {
13+
// GetLinkUUID returns the host-unique link ID.
14+
// This should be repeatable between re-constructions of the same link.
15+
GetLinkUUID() uint64
16+
17+
// GetTransportUUID returns the unique ID of the transport.
18+
GetTransportUUID() uint64
19+
// GetRemoteTransportUUID returns the reported remote transport UUID.
20+
// This should be negotiated in the handshake.
21+
GetRemoteTransportUUID() uint64
22+
23+
// GetLocalPeer returns the identity of the local peer.
24+
GetLocalPeer() peer.ID
25+
// GetRemotePeer returns the identity of the remote peer.
26+
GetRemotePeer() peer.ID
27+
28+
// OpenMountedStream opens a stream on the link, with the given parameters.
29+
OpenMountedStream(
30+
ctx context.Context,
31+
protocolID protocol.ID,
32+
opts stream.OpenOpts,
33+
) (MountedStream, error)
34+
}

link/mounted-stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type MountedStream interface {
2222
// GetPeerID returns the peer ID for the other end of the stream.
2323
GetPeerID() peer.ID
2424
// GetLink returns the associated link carrying the stream.
25-
GetLink() Link
25+
GetLink() MountedLink
2626
}
2727

2828
// MountedStreamHandler handles an incoming mounted stream.

link/open-stream-ex.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
// OpenStreamWithPeerEx executes a OpenStreamWithPeer directive.
13-
// Returns a release function for the links used for the stream.
13+
// Returns a release function for the reference to the link used for the stream.
1414
func OpenStreamWithPeerEx(
1515
ctx context.Context,
1616
b bus.Bus,
@@ -19,32 +19,26 @@ func OpenStreamWithPeerEx(
1919
transportID uint64,
2020
openOpts stream.OpenOpts,
2121
) (MountedStream, func(), error) {
22-
_, estLinkRef, err := b.AddDirective(
22+
mlnk, _, ref, err := bus.ExecWaitValue[EstablishLinkWithPeerValue](
23+
ctx,
24+
b,
2325
NewEstablishLinkWithPeer(localPeerID, remotePeerID),
2426
nil,
27+
nil,
28+
nil,
2529
)
2630
if err != nil {
31+
if ref != nil {
32+
ref.Release()
33+
}
2734
return nil, func() {}, err
2835
}
2936

30-
mstrm, _, ref, err := bus.ExecWaitValue[MountedStream](
31-
ctx,
32-
b,
33-
NewOpenStreamWithPeer(
34-
protocolID,
35-
localPeerID, remotePeerID,
36-
transportID,
37-
openOpts,
38-
),
39-
nil,
40-
nil,
41-
nil,
42-
)
37+
mstrm, err := mlnk.OpenMountedStream(ctx, protocolID, openOpts)
4338
if err != nil {
44-
estLinkRef.Release()
39+
ref.Release()
4540
return nil, func() {}, err
4641
}
47-
ref.Release()
4842

49-
return mstrm, estLinkRef.Release, nil
43+
return mstrm, ref.Release, nil
5044
}

link/open-stream-with-link-ex.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

link/open-stream-with-link.go

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)