Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.24.0 #683

Merged
merged 30 commits into from
Oct 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
171b0b7
Merge pull request #670 from ipfs/release
lidel Sep 5, 2024
43eb24b
feat: add protocol filtering
2color Sep 12, 2024
30b853c
test: improve tests
2color Sep 12, 2024
a920f23
fix: remove negative filter tests and fix filter
2color Sep 13, 2024
3dc1a58
chore: add query params conditionally
2color Sep 17, 2024
496805d
fix: tests
2color Sep 17, 2024
a4e9def
chore: update changelog
2color Sep 17, 2024
da4a194
fix: ensure protocol filter is case-insensitive
2color Sep 17, 2024
3a6de23
feat: add generic filter iterator and use for fitlering
2color Sep 24, 2024
b9958d0
feat: proto & addr filter in peer routing endpoint
2color Sep 24, 2024
0a8bebd
fix: use PeerRecord in the FindPeers
2color Sep 24, 2024
825d82f
chore: ignore check
2color Sep 24, 2024
628b0f6
ipld/unixfs/hamt: catch panic in walkChildren (#393)
Jorropo Sep 24, 2024
b6ed0dc
fix: conversion from bitswap record
2color Sep 25, 2024
f210c0d
test: add addr and protocol tests to peer handler
2color Sep 25, 2024
ef3f6b6
Apply suggestions from code review
2color Sep 25, 2024
9811e83
fix: return nil when a record doesnt pass filter
2color Sep 25, 2024
51f200a
fix: rename to protocolsAllowed for readability
2color Sep 25, 2024
d8edbe6
fix: include addresses that passed negative filters
2color Sep 25, 2024
3d2a8e5
docs: improve comments and add test
2color Sep 25, 2024
61b5def
Merge branch 'main' into add-protocol-filtering
2color Sep 25, 2024
f13c862
test: add real world test case
lidel Sep 26, 2024
137d34f
Apply suggestions from code review
2color Sep 27, 2024
4af06fd
Merge pull request #671 from ipfs/add-protocol-filtering
2color Sep 27, 2024
19a402b
feat: option to not read size of blocks for want-have requests (#672)
gammazero Sep 27, 2024
4d0ae45
feat: add protocol and address filtering to delegated routing api (#678)
2color Oct 1, 2024
d62e031
Update to latest go-libp2p (#681)
gammazero Oct 3, 2024
f61a371
update version
gammazero Oct 3, 2024
8464618
docs(changelog): v0.24.0
lidel Oct 3, 2024
eac6c25
chore: update go-multiaddr-dns (#684)
gammazero Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: improve comments and add test
  • Loading branch information
2color committed Sep 25, 2024
commit 3d2a8e5a3124d398f370f588304745918d2393ea
27 changes: 25 additions & 2 deletions routing/http/server/filters.go
Original file line number Diff line number Diff line change
@@ -20,20 +20,28 @@
}

// applyFiltersToIter applies the filters to the given iterator and returns a new iterator.
//
// The function iterates over the input iterator, applying the specified filters to each record.
// It supports both positive and negative filters for both addresses and protocols.
//
// Parameters:
// - recordsIter: An iterator of types.Record to be filtered.
// - filterAddrs: A slice of strings representing the address filter criteria.
// - filterProtocols: A slice of strings representing the protocol filter criteria.
func applyFiltersToIter(recordsIter iter.ResultIter[types.Record], filterAddrs, filterProtocols []string) iter.ResultIter[types.Record] {
mappedIter := iter.Map(recordsIter, func(v iter.Result[types.Record]) iter.Result[types.Record] {
if v.Err != nil || v.Val == nil {
return v
}

Check warning on line 35 in routing/http/server/filters.go

Codecov / codecov/patch

routing/http/server/filters.go#L34-L35

Added lines #L34 - L35 were not covered by tests

switch v.Val.GetSchema() {
case types.SchemaPeer:
record, ok := v.Val.(*types.PeerRecord)
if !ok {
logger.Errorw("problem casting find providers record", "Schema", v.Val.GetSchema(), "Type", reflect.TypeOf(v).String())
// TODO: Do we want to let failed type assertions to pass through?
return v
}

Check warning on line 44 in routing/http/server/filters.go

Codecov / codecov/patch

routing/http/server/filters.go#L41-L44

Added lines #L41 - L44 were not covered by tests

record = applyFilters(record, filterAddrs, filterProtocols)
if record == nil {
@@ -46,15 +54,15 @@
//lint:ignore SA1019 // ignore staticcheck
record, ok := v.Val.(*types.BitswapRecord)
if !ok {
logger.Errorw("problem casting find providers record", "Schema", v.Val.GetSchema(), "Type", reflect.TypeOf(v).String())
// TODO: Do we want to let failed type assertions to pass through?
return v
}

Check warning on line 60 in routing/http/server/filters.go

Codecov / codecov/patch

routing/http/server/filters.go#L57-L60

Added lines #L57 - L60 were not covered by tests
peerRecord := types.FromBitswapRecord(record)
peerRecord = applyFilters(peerRecord, filterAddrs, filterProtocols)
if peerRecord == nil {
return iter.Result[types.Record]{}
}

Check warning on line 65 in routing/http/server/filters.go

Codecov / codecov/patch

routing/http/server/filters.go#L64-L65

Added lines #L64 - L65 were not covered by tests
v.Val = peerRecord
}
return v
@@ -69,35 +77,35 @@
}

//lint:ignore U1000 // ignore unused
func filterRecords(records []types.Record, filterAddrs, filterProtocols []string) []types.Record {
if len(filterAddrs) == 0 && len(filterProtocols) == 0 {
return records
}

Check warning on line 83 in routing/http/server/filters.go

Codecov / codecov/patch

routing/http/server/filters.go#L80-L83

Added lines #L80 - L83 were not covered by tests

filtered := make([]types.Record, 0, len(records))

for _, record := range records {
// TODO: Handle SchemaBitswap
if schema := record.GetSchema(); schema == types.SchemaPeer {
peer, ok := record.(*types.PeerRecord)
if !ok {
logger.Errorw("problem casting find providers result", "Schema", record.GetSchema(), "Type", reflect.TypeOf(record).String())
// if the type assertion fails, we exlude record from results
continue

Check warning on line 94 in routing/http/server/filters.go

Codecov / codecov/patch

routing/http/server/filters.go#L85-L94

Added lines #L85 - L94 were not covered by tests
}

record := applyFilters(peer, filterAddrs, filterProtocols)

if record != nil {
filtered = append(filtered, record)
}

Check warning on line 101 in routing/http/server/filters.go

Codecov / codecov/patch

routing/http/server/filters.go#L97-L101

Added lines #L97 - L101 were not covered by tests

} else {
// Will we ever encounter the SchemaBitswap type? Evidence seems to suggest that no longer
logger.Errorw("encountered unknown provider schema", "Schema", record.GetSchema(), "Type", reflect.TypeOf(record).String())
}

Check warning on line 106 in routing/http/server/filters.go

Codecov / codecov/patch

routing/http/server/filters.go#L103-L106

Added lines #L103 - L106 were not covered by tests
}
return filtered

Check warning on line 108 in routing/http/server/filters.go

Codecov / codecov/patch

routing/http/server/filters.go#L108

Added line #L108 was not covered by tests
}

// Applies the filters. Returns nil if the provider does not pass the protocols filter
@@ -128,8 +136,23 @@
return provider
}

// If there are only negative filters, no addresses will be included in the result. The function will return an empty list.
// For an address to be included, it must pass all negative filters
// applyAddrFilter filters a list of multiaddresses based on the provided filter query.
//
// Parameters:
// - addrs: A slice of types.Multiaddr to be filtered.
// - filterAddrsQuery: A slice of strings representing the filter criteria.
//
// The function supports both positive and negative filters:
// - Positive filters (e.g., "tcp", "udp") include addresses that match the specified protocols.
// - Negative filters (e.g., "!tcp", "!udp") exclude addresses that match the specified protocols.
//
// If no filters are provided, the original list of addresses is returned unchanged.
// If only negative filters are provided, addresses not matching any negative filter are included.
// If positive filters are provided, only addresses matching at least one positive filter (and no negative filters) are included.
// If both positive and negative filters are provided, the address must match at least one positive filter and no negative filters to be included.
//
// Returns:
// A new slice of types.Multiaddr containing only the addresses that pass the filter criteria.
func applyAddrFilter(addrs []types.Multiaddr, filterAddrsQuery []string) []types.Multiaddr {
if len(filterAddrsQuery) == 0 {
return addrs
5 changes: 5 additions & 0 deletions routing/http/server/filters_test.go
Original file line number Diff line number Diff line change
@@ -62,6 +62,11 @@ func TestApplyAddrFilter(t *testing.T) {
filterAddrs: []string{"!tcp"},
expectedAddrs: []types.Multiaddr{{Multiaddr: addr2}, {Multiaddr: addr5}, {Multiaddr: addr6}, {Multiaddr: addr8}},
},
{
name: "Filter TCP addresses that don't have WebSocket and p2p-circuit",
filterAddrs: []string{"tcp", "!ws", "!wss", "!p2p-circuit"},
expectedAddrs: []types.Multiaddr{{Multiaddr: addr1}},
},
{
name: "Include WebTransport and exclude p2p-circuit",
filterAddrs: []string{"webtransport", "!p2p-circuit"},
Loading