Skip to content

Commit

Permalink
Log more details when a blocked error happens
Browse files Browse the repository at this point in the history
  • Loading branch information
hsanjuan committed Oct 3, 2023
1 parent dd200a1 commit 1815bc1
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions ipfs/blockservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (nbs *BlockService) Close() error {
// Gets a block unless CID has been blocked.
func (nbs *BlockService) GetBlock(ctx context.Context, c cid.Cid) (blocks.Block, error) {
if err := nbs.blocker.IsCidBlocked(c).ToError(); err != nil {
logger.Error(err)
logger.Error(err.Response)
return nil, err
}
return nbs.bs.GetBlock(ctx, c)
Expand All @@ -50,7 +50,7 @@ func (nbs *BlockService) GetBlocks(ctx context.Context, ks []cid.Cid) <-chan blo
var filtered []cid.Cid
for _, c := range ks {
if err := nbs.blocker.IsCidBlocked(c).ToError(); err != nil {
logger.Error(err)
logger.Error(err.Response)
logger.Warnf("GetBlocks dropped blocked block: %s", err)
} else {
filtered = append(filtered, c)
Expand All @@ -72,7 +72,7 @@ func (nbs *BlockService) Exchange() exchange.Interface {
// AddBlock adds a block unless the CID is blocked.
func (nbs *BlockService) AddBlock(ctx context.Context, o blocks.Block) error {
if err := nbs.blocker.IsCidBlocked(o.Cid()).ToError(); err != nil {
logger.Error(err)
logger.Error(err.Response)
return err
}
return nbs.bs.AddBlock(ctx, o)
Expand All @@ -83,7 +83,7 @@ func (nbs *BlockService) AddBlocks(ctx context.Context, bs []blocks.Block) error
var filtered []blocks.Block
for _, o := range bs {
if err := nbs.blocker.IsCidBlocked(o.Cid()).ToError(); err != nil {
logger.Error(err)
logger.Error(err.Response)
logger.Warnf("AddBlocks dropped blocked block: %s", err)
} else {
filtered = append(filtered, o)
Expand Down
2 changes: 1 addition & 1 deletion ipfs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ipfs-shipyard/nopfs/ipfs
go 1.20

require (
github.com/ipfs-shipyard/nopfs v0.0.7
github.com/ipfs-shipyard/nopfs v0.0.11
github.com/ipfs/boxo v0.13.1
github.com/ipfs/go-block-format v0.1.2
github.com/ipfs/go-cid v0.4.1
Expand Down
4 changes: 2 additions & 2 deletions ipfs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uG
github.com/hashicorp/golang-lru/v2 v2.0.5 h1:wW7h1TG88eUIJ2i69gaE3uNVtEPIagzhGvHgwfx2Vm4=
github.com/hashicorp/golang-lru/v2 v2.0.5/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY=
github.com/ipfs-shipyard/nopfs v0.0.7 h1:zuC9r1fNO4ijxsNFwXXQqQC7uSe9GfTMvThBkMSs4Vs=
github.com/ipfs-shipyard/nopfs v0.0.7/go.mod h1:zCmxRNQBYwTRYemK6zcKBGLKN9DkDJYNzmNMqw9GtIA=
github.com/ipfs-shipyard/nopfs v0.0.11 h1:+JrOqVs4Za0eu4jntdAqxoWolWcmtJnTQXxn2Y/Io2E=
github.com/ipfs-shipyard/nopfs v0.0.11/go.mod h1:zCmxRNQBYwTRYemK6zcKBGLKN9DkDJYNzmNMqw9GtIA=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.13.1 h1:nQ5oQzcMZR3oL41REJDcTbrvDvuZh3J9ckc9+ILeRQI=
Expand Down
4 changes: 2 additions & 2 deletions ipfs/namesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func WrapNameSystem(ns namesys.NameSystem, blocker *nopfs.Blocker) namesys.NameS
// Resolve resolves an IPNS name unless it is blocked.
func (ns *NameSystem) Resolve(ctx context.Context, name string, options ...opts.ResolveOpt) (path.Path, error) {
if err := ns.blocker.IsPathBlocked(path.FromString(name)).ToError(); err != nil {
logger.Error(err)
logger.Error(err.Response)
return "", err
}
return ns.ns.Resolve(ctx, name, options...)
Expand All @@ -41,7 +41,7 @@ func (ns *NameSystem) Resolve(ctx context.Context, name string, options ...opts.
func (ns *NameSystem) ResolveAsync(ctx context.Context, name string, options ...opts.ResolveOpt) <-chan namesys.Result {
status := ns.blocker.IsPathBlocked(path.FromString(name))
if err := status.ToError(); err != nil {
logger.Error(err)
logger.Error(err.Response)
ch := make(chan namesys.Result, 1)
ch <- namesys.Result{
Path: status.Path,
Expand Down
6 changes: 3 additions & 3 deletions ipfs/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func WrapResolver(res resolver.Resolver, blocker *nopfs.Blocker) resolver.Resolv
// ResolveToLastNode checks if the given path is blocked before resolving.
func (res *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (cid.Cid, []string, error) {
if err := res.blocker.IsPathBlocked(fpath).ToError(); err != nil {
logger.Error(err)
logger.Error(err.Response)
return cid.Undef, nil, err
}
return res.resolver.ResolveToLastNode(ctx, fpath)
Expand All @@ -40,7 +40,7 @@ func (res *Resolver) ResolveToLastNode(ctx context.Context, fpath path.Path) (ci
// ResolvePath checks if the given path is blocked before resolving.
func (res *Resolver) ResolvePath(ctx context.Context, fpath path.Path) (ipld.Node, ipld.Link, error) {
if err := res.blocker.IsPathBlocked(fpath).ToError(); err != nil {
logger.Error(err)
logger.Error(err.Response)
return nil, nil, err
}
return res.resolver.ResolvePath(ctx, fpath)
Expand All @@ -49,7 +49,7 @@ func (res *Resolver) ResolvePath(ctx context.Context, fpath path.Path) (ipld.Nod
// ResolvePathComponents checks if the given path is blocked before resolving.
func (res *Resolver) ResolvePathComponents(ctx context.Context, fpath path.Path) ([]ipld.Node, error) {
if err := res.blocker.IsPathBlocked(fpath).ToError(); err != nil {
logger.Error(err)
logger.Error(err.Response)
return nil, err
}
return res.resolver.ResolvePathComponents(ctx, fpath)
Expand Down

0 comments on commit 1815bc1

Please sign in to comment.