|
|
|
@ -88,9 +88,9 @@ type Registry struct { |
|
|
|
|
intervalsStore state.Store |
|
|
|
|
autoRetrieval bool // automatically subscribe to retrieve request stream
|
|
|
|
|
maxPeerServers int |
|
|
|
|
spec *protocols.Spec //this protocol's spec
|
|
|
|
|
balance protocols.Balance // implements protocols.Balance, for accounting
|
|
|
|
|
prices protocols.Prices // implements protocols.Prices, provides prices to accounting
|
|
|
|
|
spec *protocols.Spec // this protocol's spec
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// RegistryOptions holds optional values for NewRegistry constructor.
|
|
|
|
@ -110,7 +110,7 @@ func NewRegistry(localID enode.ID, delivery *Delivery, syncChunkStore storage.Sy |
|
|
|
|
if options.SyncUpdateDelay <= 0 { |
|
|
|
|
options.SyncUpdateDelay = 15 * time.Second |
|
|
|
|
} |
|
|
|
|
//check if retriaval has been disabled
|
|
|
|
|
// check if retrieval has been disabled
|
|
|
|
|
retrieval := options.Retrieval != RetrievalDisabled |
|
|
|
|
|
|
|
|
|
streamer := &Registry{ |
|
|
|
@ -235,10 +235,14 @@ func NewRegistry(localID enode.ID, delivery *Delivery, syncChunkStore storage.Sy |
|
|
|
|
return streamer |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// This is an accounted protocol, therefore we need to provide a pricing Hook to the spec
|
|
|
|
|
// For simulations to be able to run multiple nodes and not override the hook's balance,
|
|
|
|
|
// we need to construct a spec instance per node instance
|
|
|
|
|
func (r *Registry) setupSpec() { |
|
|
|
|
// first create the "bare" spec
|
|
|
|
|
r.createSpec() |
|
|
|
|
// now create the pricing object
|
|
|
|
|
r.createPriceOracle() |
|
|
|
|
// if balance is nil, this node has been started without swap support (swapEnabled flag is false)
|
|
|
|
|
if r.balance != nil && !reflect.ValueOf(r.balance).IsNil() { |
|
|
|
|
// swap is enabled, so setup the hook
|
|
|
|
@ -756,6 +760,52 @@ func (r *Registry) createSpec() { |
|
|
|
|
r.spec = spec |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// An accountable message needs some meta information attached to it
|
|
|
|
|
// in order to evaluate the correct price
|
|
|
|
|
type StreamerPrices struct { |
|
|
|
|
priceMatrix map[reflect.Type]*protocols.Price |
|
|
|
|
registry *Registry |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Price implements the accounting interface and returns the price for a specific message
|
|
|
|
|
func (sp *StreamerPrices) Price(msg interface{}) *protocols.Price { |
|
|
|
|
t := reflect.TypeOf(msg).Elem() |
|
|
|
|
return sp.priceMatrix[t] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Instead of hardcoding the price, get it
|
|
|
|
|
// through a function - it could be quite complex in the future
|
|
|
|
|
func (sp *StreamerPrices) getRetrieveRequestMsgPrice() uint64 { |
|
|
|
|
return uint64(1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Instead of hardcoding the price, get it
|
|
|
|
|
// through a function - it could be quite complex in the future
|
|
|
|
|
func (sp *StreamerPrices) getChunkDeliveryMsgRetrievalPrice() uint64 { |
|
|
|
|
return uint64(1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// createPriceOracle sets up a matrix which can be queried to get
|
|
|
|
|
// the price for a message via the Price method
|
|
|
|
|
func (r *Registry) createPriceOracle() { |
|
|
|
|
sp := &StreamerPrices{ |
|
|
|
|
registry: r, |
|
|
|
|
} |
|
|
|
|
sp.priceMatrix = map[reflect.Type]*protocols.Price{ |
|
|
|
|
reflect.TypeOf(ChunkDeliveryMsgRetrieval{}): { |
|
|
|
|
Value: sp.getChunkDeliveryMsgRetrievalPrice(), // arbitrary price for now
|
|
|
|
|
PerByte: true, |
|
|
|
|
Payer: protocols.Receiver, |
|
|
|
|
}, |
|
|
|
|
reflect.TypeOf(RetrieveRequestMsg{}): { |
|
|
|
|
Value: sp.getRetrieveRequestMsgPrice(), // arbitrary price for now
|
|
|
|
|
PerByte: false, |
|
|
|
|
Payer: protocols.Sender, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
r.prices = sp |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (r *Registry) Protocols() []p2p.Protocol { |
|
|
|
|
return []p2p.Protocol{ |
|
|
|
|
{ |
|
|
|
|