rpc

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package rpc implements the rpc layer for the bloomfilter, following the principles from https://golang.org/pkg/net/rpc

Example (Integration)
client, err := rpc.Dial("tcp", "127.0.0.1:1234")
if err != nil {
	fmt.Printf("dialing error: %s", err.Error())
	return
}

var (
	addOutput   AddOutput
	checkOutput CheckOutput
	unionOutput UnionOutput
	elems1      = [][]byte{[]byte("rrrr"), []byte("elem2")}
	elems2      = [][]byte{[]byte("house")}
	elems3      = [][]byte{[]byte("house"), []byte("mouse")}
	cfg         = rotate.Config{
		Config: bloomfilter.Config{
			N:        10000000,
			P:        0.0000001,
			HashName: "optimal",
		},
		TTL: 1500,
	}
)

err = client.Call("BloomfilterRPC.Add", AddInput{elems1}, &addOutput)
if err != nil {
	fmt.Printf("unexpected error: %s", err.Error())
	return
}

err = client.Call("BloomfilterRPC.Check", CheckInput{elems1}, &checkOutput)
if err != nil {
	fmt.Printf("unexpected error: %s", err.Error())
	return
}
if len(checkOutput.Checks) != 2 || !checkOutput.Checks[0] || !checkOutput.Checks[1] {
	fmt.Printf("checks error, expected true elements")
	return
}

divCall := client.Go("BloomfilterRPC.Check", elems1, &checkOutput, nil)
<-divCall.Done

if len(checkOutput.Checks) != 2 || !checkOutput.Checks[0] || !checkOutput.Checks[1] {
	fmt.Printf("checks error, expected true elements")
	return
}

var bf2 = rotate.New(context.Background(), cfg)
bf2.Add([]byte("house"))

err = client.Call("BloomfilterRPC.Union", UnionInput{bf2}, &unionOutput)
if err != nil {
	fmt.Printf("unexpected error: %s", err.Error())
	return
}
fmt.Println(unionOutput.Capacity < 1e-6)

err = client.Call("BloomfilterRPC.Check", CheckInput{elems2}, &checkOutput)
if err != nil {
	fmt.Printf("unexpected error: %s", err.Error())
	return
}
fmt.Println(checkOutput.Checks)
if len(checkOutput.Checks) != 1 || !checkOutput.Checks[0] {
	fmt.Println("checks error, expected true element")
	return
}

var bf3 = rotate.New(context.Background(), cfg)
bf3.Add([]byte("mouse"))

divCall = client.Go("BloomfilterRPC.Union", UnionInput{bf3}, &unionOutput, nil)
<-divCall.Done

err = client.Call("BloomfilterRPC.Check", CheckInput{elems3}, &checkOutput)
if err != nil {
	fmt.Printf("unexpected error: %s", err.Error())
	return
}

fmt.Println(unionOutput.Capacity < 1e-6)
fmt.Println(checkOutput.Checks)
if len(checkOutput.Checks) != 2 || !checkOutput.Checks[0] || !checkOutput.Checks[1] {
	fmt.Println("checks error, expected true element")
	return
}
Output:

true
[true]
true
[true true]

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNoBloomfilterInitialized = fmt.Errorf("Bloomfilter not initialized")
)

ErrNoBloomfilterInitialized error

Functions

This section is empty.

Types

type AddInput

type AddInput struct {
	Elems [][]byte
}

AddInput type for an array of elements

type AddOutput

type AddOutput struct {
	Count int
}

AddOutput type for an array of elements to a sliding bloomfilter set

type Bloomfilter

type Bloomfilter struct {
	BloomfilterRPC
}

Bloomfilter wrapper for BloomfilterRPC type

func New

func New(ctx context.Context, cfg Config) *Bloomfilter

New rpc layer implementation of creating a sliding bloomfilter set

func (*Bloomfilter) Bloomfilter

func (b *Bloomfilter) Bloomfilter() *rotate.Bloomfilter

Bloomfilter getter

func (*Bloomfilter) Close

func (b *Bloomfilter) Close()

Close sliding bloomfilter set

type BloomfilterRPC

type BloomfilterRPC int

BloomfilterRPC type

func (*BloomfilterRPC) Add

func (b *BloomfilterRPC) Add(in AddInput, out *AddOutput) error

Add rpc layer implementation of an array of elements to a sliding bloomfilter set

func (*BloomfilterRPC) Check

func (b *BloomfilterRPC) Check(in CheckInput, out *CheckOutput) error

Check rpc layer implementation of an array of elements in a sliding bloomfilter set

func (*BloomfilterRPC) Union

func (b *BloomfilterRPC) Union(in UnionInput, out *UnionOutput) error

Union rpc layer implementation of two sliding bloomfilter sets

type CheckInput

type CheckInput struct {
	Elems [][]byte
}

CheckInput type for an array of elements

type CheckOutput

type CheckOutput struct {
	Checks []bool
}

CheckOutput type for check result of an array of elements in a sliding bloomfilter set

type Config

type Config struct {
	rotate.Config
	Port int
}

Config type containing a sliding bloomfilter set and a port

type UnionInput

type UnionInput struct {
	BF *rotate.Bloomfilter
}

UnionInput type for sliding bloomfilter set

type UnionOutput

type UnionOutput struct {
	Capacity float64
}

UnionOutput type for sliding bloomfilter set fill degree

Directories

Path Synopsis
Package client implements an rpc client for the bloomfilter, along with Add and Check methods.
Package client implements an rpc client for the bloomfilter, along with Add and Check methods.
Package server implements an rpc server for the bloomfilter, registering a bloomfilter and accepting a tcp listener.
Package server implements an rpc server for the bloomfilter, registering a bloomfilter and accepting a tcp listener.

Jump to

Keyboard shortcuts

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