Skip to content

Commit

Permalink
feat: initial peer-sharing support (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney authored Apr 10, 2024
1 parent 32fb9ca commit 8b43b26
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
11 changes: 11 additions & 0 deletions listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"net"

ouroboros "github.com/blinklabs-io/gouroboros"
"github.com/blinklabs-io/gouroboros/protocol/peersharing"
)

type ListenerConfig struct {
Expand All @@ -35,6 +36,16 @@ func (n *Node) startListener(l ListenerConfig) {
ouroboros.WithPeerSharing(n.config.peerSharing),
// TODO: add protocol configs to configure callback functions
}
if n.config.peerSharing {
defaultConnOpts = append(
defaultConnOpts,
ouroboros.WithPeerSharingConfig(
peersharing.NewConfig(
peersharing.WithShareRequestFunc(n.peersharingShareRequest),
),
),
)
}
for {
// Accept connection
conn, err := l.Listener.Accept()
Expand Down
1 change: 0 additions & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (n *Node) Run() error {

// Wait forever
select {}
return nil
}

func (n *Node) connectionManagerConnClosed(connId ouroboros.ConnectionId, err error) {
Expand Down
24 changes: 24 additions & 0 deletions peersharing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package node

import (
"github.com/blinklabs-io/gouroboros/protocol/peersharing"
)

func (n *Node) peersharingShareRequest(ctx peersharing.CallbackContext, amount int) ([]peersharing.PeerAddress, error) {
// TODO: add hooks for getting peers to share
return []peersharing.PeerAddress{}, nil
}

0 comments on commit 8b43b26

Please sign in to comment.