proxy

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2016 License: GPL-3.0 Imports: 12 Imported by: 3

Documentation

Overview

Package proxy implements the HTTP payment proxy between a locally exposed endpoint and the public internet.

Index

Constants

View Source
const (
	AuthorizationHeader = "etherapi-authorization" // Client side payment authorization header
	VerificationHeader  = "etherapi-verification"  // Server side payment verification header
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Charger

type Charger interface {
	// Charge calls down into the underlying Ethereum contract layer and executes
	// a payment charging transaction. It returns the hex encoded transaction id
	// to enable later verification.
	Charge(from, to common.Address, nonce uint64, amount *big.Int, signature []byte) (common.Hash, error)
}

Charger chaaaaarges! :D Fun's aside, this interfaces provides the capability to redeem an authorized payment by the underlying framework.

type Proxy

type Proxy struct {
	// contains filtered or unexported fields
}

Proxy is a payment gateway between arbitrarily many internal services and the outside world. Its role is to broker API requests between them, while at the same time enforcing payment authorizations.

func New

func New(id int, extPort, intPort int, kind ProxyType, verifier Verifier, vault *Vault) *Proxy

New creates a new payment proxy between an internal and external world.

func (*Proxy) ServeHTTP

func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler, extracting and validating payment headers contained within the HTTP request. If payment information is accepted, the request is passed on to the internal service for execution. Otherwise the proxy short circuits the request and sends back an appropriate error.

func (*Proxy) Start

func (p *Proxy) Start() error

Start boots up the proxy, opening up the HTTP listeners towards the internally available service.

Note, the method will block forever.

type ProxyType

type ProxyType int

ProxyType is the various types of proxies that can be created.

const (
	CallProxy ProxyType = iota // Payment units are authorized and charged per API call
	DataProxy                  // Payment units are authorized and charged per data traffic
)

type Vault

type Vault struct {
	// contains filtered or unexported fields
}

Vault is a payment aggregator collecting the individual accepted payments made by various clients. It can at any point return the most recent payment + proof, and can also charge the payments via the Ethereum network.

func NewVault

func NewVault(charger Charger) *Vault

NewVault create and returns an empty vault ready for accepting payments.

func (*Vault) AutoCharge

func (v *Vault) AutoCharge(interval time.Duration)

AutoCharge starts a periodical automatic charging to claim collected funds.

func (*Vault) Charge

func (v *Vault) Charge()

Charge will redeem all pending payments from the vault.

func (*Vault) Fetch

func (v *Vault) Fetch(provider, consumer common.Address) *authorization

Fetch retrieves the last known authorization made by a particular consumer to a particular provider.

func (*Vault) Store

func (v *Vault) Store(auth *authorization)

Store inserts a new authorized payment into the vault for later redemption.

type Verifier

type Verifier interface {
	// Exists checks whether there's a live payment channel already set up between
	// the sender and recipient.
	Exists(from, to common.Address) bool

	// Verify checks whether the authorization is cryptographically valid, and also
	// whether there are enough funds in the payment channel to process this payment.
	Verify(from, to common.Address, nonce uint64, amount *big.Int, signature []byte) (bool, bool)

	// Price returns the price provided by the signature of (from || to).
	Price(from, to common.Address) *big.Int
	// Nonce returns the nonce provided by the signature of (from || to).
	Nonce(from, to common.Address) *big.Int
}

Verifier is an interface that accepts the details of a payment authorization and returns whether the sender is allowed to make the payment or not.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL