(ctx context.Context, ep blobcache.Endpoint, req Message, resp *Message)
| 24 | } |
| 25 | |
| 26 | func (s *Server) ServeBCP(ctx context.Context, ep blobcache.Endpoint, req Message, resp *Message) bool { |
| 27 | svc := s.Access(ep.Node) |
| 28 | if svc == nil { |
| 29 | return false |
| 30 | } |
| 31 | |
| 32 | switch req.Header().Code() { |
| 33 | case MT_PING: |
| 34 | resp.SetCode(MT_OK) |
| 35 | resp.SetBody(nil) |
| 36 | case MT_ENDPOINT: |
| 37 | handleAsk(req, resp, &EndpointReq{}, func(req *EndpointReq) (*EndpointResp, error) { |
| 38 | ep, err := svc.Endpoint(ctx) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | return &EndpointResp{Endpoint: ep}, nil |
| 43 | }) |
| 44 | |
| 45 | // BEGIN HANDLE |
| 46 | case MT_HANDLE_DROP: |
| 47 | handleAsk(req, resp, &DropReq{}, func(req *DropReq) (*DropResp, error) { |
| 48 | if err := svc.Drop(ctx, req.Handle); err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | return &DropResp{}, nil |
| 52 | }) |
| 53 | case MT_HANDLE_INSPECT: |
| 54 | handleAsk(req, resp, &InspectHandleReq{}, func(req *InspectHandleReq) (*InspectHandleResp, error) { |
| 55 | info, err := svc.InspectHandle(ctx, req.Handle) |
| 56 | if err != nil { |
| 57 | return nil, err |
| 58 | } |
| 59 | return &InspectHandleResp{Info: *info}, nil |
| 60 | }) |
| 61 | case MT_HANDLE_KEEP_ALIVE: |
| 62 | handleAsk(req, resp, &KeepAliveReq{}, func(req *KeepAliveReq) (*KeepAliveResp, error) { |
| 63 | if err := svc.KeepAlive(ctx, req.Handles); err != nil { |
| 64 | return nil, err |
| 65 | } |
| 66 | return &KeepAliveResp{}, nil |
| 67 | }) |
| 68 | case MT_HANDLE_SHARE_OUT: |
| 69 | handleAsk(req, resp, &ShareOutReq{}, func(req *ShareOutReq) (*ShareOutResp, error) { |
| 70 | h, err := svc.ShareOut(ctx, req.Handle, req.Peer, req.Mask) |
| 71 | if err != nil { |
| 72 | return nil, err |
| 73 | } |
| 74 | return &ShareOutResp{Handle: *h}, nil |
| 75 | }) |
| 76 | case MT_HANDLE_SHARE_IN: |
| 77 | handleAsk(req, resp, &ShareInReq{}, func(req *ShareInReq) (*ShareInResp, error) { |
| 78 | h, err := svc.ShareIn(ctx, req.Host, req.Handle) |
| 79 | if err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | return &ShareInResp{Handle: h}, nil |
| 83 | }) |
nothing calls this directly
no test coverage detected