Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
839 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
syntax = "proto3"; | ||
|
||
package tinder; | ||
|
||
import "github.com/gogo/protobuf/gogoproto/gogo.proto"; | ||
|
||
option go_package = "berty.tech/berty/go/internal/tinder"; | ||
|
||
option (gogoproto.goproto_enum_prefix_all) = false; | ||
option (gogoproto.marshaler_all) = true; | ||
option (gogoproto.unmarshaler_all) = true; | ||
option (gogoproto.sizer_all) = true; | ||
|
||
message LocalRecord { | ||
map<string, int64> records = 1; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package ipfsutil | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
mcma "berty.tech/berty/v2/go/internal/multipeer-connectivity-transport/multiaddr" | ||
ipfs_core "github.com/ipfs/go-ipfs/core" | ||
ipfs_interface "github.com/ipfs/interface-go-ipfs-core" | ||
"github.com/libp2p/go-libp2p-core/host" | ||
"github.com/libp2p/go-libp2p-core/network" | ||
"github.com/libp2p/go-libp2p-core/protocol" | ||
ma "github.com/multiformats/go-multiaddr" | ||
manet "github.com/multiformats/go-multiaddr-net" | ||
) | ||
|
||
const recProtocolID = protocol.ID("berty/p2p/localrecord") | ||
|
||
type LocalRecord struct { | ||
host host.Host | ||
} | ||
|
||
// OptionLocalRecord is given to CoreAPIOption.Options when the ipfs node setup | ||
func OptionLocalRecord(ctx context.Context, node *ipfs_core.IpfsNode, api ipfs_interface.CoreAPI) error { | ||
lr := &LocalRecord{ | ||
host: node.PeerHost, | ||
} | ||
lr.host.Network().Notify(lr) | ||
lr.host.SetStreamHandler(recProtocolID, lr.handleLocalRecords) | ||
|
||
return nil | ||
} | ||
|
||
// called when network starts listening on an addr | ||
func (lr *LocalRecord) Listen(network.Network, ma.Multiaddr) {} | ||
|
||
// called when network stops listening on an addr | ||
func (lr *LocalRecord) ListenClose(network.Network, ma.Multiaddr) {} | ||
|
||
// called when a connection opened | ||
func (lr *LocalRecord) Connected(net network.Network, c network.Conn) { | ||
go func() { | ||
if manet.IsPrivateAddr(c.RemoteMultiaddr()) || mcma.MC.Matches(c.RemoteMultiaddr()) { | ||
if err := lr.sendLocalRecord(c); err != nil { | ||
return | ||
} | ||
} | ||
}() | ||
} | ||
|
||
// called when a connection closed | ||
func (lr *LocalRecord) Disconnected(network.Network, network.Conn) {} | ||
|
||
// called when a stream opened | ||
func (lr *LocalRecord) OpenedStream(network.Network, network.Stream) {} | ||
|
||
// called when a stream closed | ||
func (lr *LocalRecord) ClosedStream(network.Network, network.Stream) {} | ||
|
||
func (lr *LocalRecord) sendLocalRecord(c network.Conn) error { | ||
s, err := c.NewStream() | ||
if err != nil { | ||
return err | ||
} | ||
s.SetProtocol(recProtocolID) | ||
return nil | ||
} | ||
|
||
func (lr *LocalRecord) handleLocalRecords(s network.Stream) { | ||
os.Stderr.WriteString("handleLocalRecords") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.