ipfs/go-graphsync

Discussion: Unify imperative commands

hannahhoward opened this issue · 2 comments

When RequestID was an int, it didn't uniquely identify requests and responses. Now it does!

Which means we can potentially simplify our imperative methos significantly:

// GraphExchange is a protocol that can exchange IPLD graphs based on a selector
type GraphExchange interface {

        // ...
        
	// UnpauseRequest unpauses a request that was paused in a block hook based request ID
	// Can also send extensions with unpause
	UnpauseRequest(RequestID, ...ExtensionData) error

	// PauseRequest pauses an in progress request (may take 1 or more blocks to process)
	PauseRequest(RequestID) error

	// UnpauseResponse unpauses a response that was paused in a block hook based on peer ID and request ID
	// Can also send extensions with unpause
	UnpauseResponse(peer.ID, RequestID, ...ExtensionData) error

	// PauseResponse pauses an in progress response (may take 1 or more blocks to process)
	PauseResponse(peer.ID, RequestID) error

	// CancelResponse cancels an in progress response
	CancelResponse(peer.ID, RequestID) error

	// CancelRequest cancels an in progress request
	CancelRequest(context.Context, RequestID) error
	
	// ...
}

Can become:

// GraphExchange is a protocol that can exchange IPLD graphs based on a selector
type GraphExchange interface {

        // ...
        
        // added context on all these for good measure
        
	// Unpause unpauses a request/response that was paused
	// Can also send extensions with unpause
	Unpause(context.Context, RequestID, ...ExtensionData) error

	// Pause pauses an in progress request/response
	Pause(context.Context, RequestID) error

	// Cancels and in progress request/response
	Cancel(context.Context, RequestID) error

	// ...
}

Algorithmically, it should pretty straight forward to implement these. Just run the requestor side first -- if nothing matches, move on to responder

rvagg commented

nice, +1