forked from filecoin-project/boost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
44 lines (36 loc) · 1.34 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package transport
import (
"context"
"encoding/json"
"fmt"
smtypes "github.com/filecoin-project/boost/storagemarket/types"
"github.com/filecoin-project/boost/transport/types"
)
//go:generate go run github.com/golang/mock/mockgen -destination=mocks/mock_transport.go -package=mocks . Transport,Handler
type Transport interface {
Execute(ctx context.Context, transportInfo []byte, dealInfo *types.TransportDealInfo) (th Handler, err error)
}
type Handler interface {
Sub() chan types.TransportEvent
Close()
}
func TransferParamsAsJson(transfer smtypes.Transfer) (string, error) {
if transfer.Type != "http" && transfer.Type != "libp2p" {
return "", fmt.Errorf("cannot parse params for unrecognized transfer type '%s'", transfer.Type)
}
// de-serialize transport opaque token
tInfo := &types.HttpRequest{}
if err := json.Unmarshal(transfer.Params, tInfo); err != nil {
return "", fmt.Errorf("failed to de-serialize transport params bytes '%s': %w", string(transfer.Params), err)
}
// Just extract the URL, not the headers, because the headers may contain
// sensitive information that we don't want to end up in a log file
// somewhere (eg Authorization header)
bz, err := json.Marshal(map[string]string{
"URL": tInfo.URL,
})
if err != nil {
return "", fmt.Errorf("marshalling transfer params json: %w", err)
}
return string(bz), nil
}