link

package
v0.0.0-...-ae41d0e Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

DSPrototocols is a project that implements some of the protocols of the book written by Christian Cachin, Rachid Guerraoui and Luís Rodrigues "Introduction to Reliable and Secure Distributed Programming", second edition, (https://www.distributedprogramming.net/), implemented during the 2018 class "Tópicos especiais em processamento paralelo e distribuído II" at Pontifícia Universidade Católica - RS, Brazil, under supervision of professor Fernando Luis Dotti.

Copyright (C) 2018

Atila Leites Romero (atilaromero@gmail.com),
Carlos Renan Schick Louzada (crenan.louzada@gmail.com),
Eliã Rafael de Lima Batista (o.elia.batista@gmail.com),
Tarcisio Ceolin Junior (tarcisio@ceolin.org)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

DSPrototocols is a project that implements some of the protocols of the book written by Christian Cachin, Rachid Guerraoui and Luís Rodrigues "Introduction to Reliable and Secure Distributed Programming", second edition, (https://www.distributedprogramming.net/), implemented during the 2018 class "Tópicos especiais em processamento paralelo e distribuído II" at Pontifícia Universidade Católica - RS, Brazil, under supervision of professor Fernando Luis Dotti.

Copyright (C) 2018

Atila Leites Romero (atilaromero@gmail.com),
Carlos Renan Schick Louzada (crenan.louzada@gmail.com),
Eliã Rafael de Lima Batista (o.elia.batista@gmail.com),
Tarcisio Ceolin Junior (tarcisio@ceolin.org)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

DSPrototocols is a project that implements some of the protocols of the book written by Christian Cachin, Rachid Guerraoui and Luís Rodrigues "Introduction to Reliable and Secure Distributed Programming", second edition, (https://www.distributedprogramming.net/), implemented during the 2018 class "Tópicos especiais em processamento paralelo e distribuído II" at Pontifícia Universidade Católica - RS, Brazil, under supervision of professor Fernando Luis Dotti.

Copyright (C) 2018

Atila Leites Romero (atilaromero@gmail.com),
Carlos Renan Schick Louzada (crenan.louzada@gmail.com),
Eliã Rafael de Lima Batista (o.elia.batista@gmail.com),
Tarcisio Ceolin Junior (tarcisio@ceolin.org)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Link interface {
	Send(id int, payload []byte) error
	GetDeliver() <-chan Message
	ID() int
}

Link is a struct that contains the ID of a process and 2 channels: Link receives messages from a upper layer through Req and deliver messages through Ind.

func NewByChan

func NewByChan(id int, peers map[int]chan<- Message) Link

NewByChan returns a new Pl struct. This implementations uses only channels, instead of sockets, designed to be used in a non distributed environment (single machine).

For a network implementation with similar behavior, see XXX...XXX

ID refers to the process than owns this Pl. peers is a, possibly empty, pool of all Pl. NewPl will modify this pool, incluing the new Pl in it.

The requisition channel is used to receive messages from the upper layer.

Ex: pl.Req <- msg

When a new message is received through Req, that message's destination is seeked in the pool of perfect links (peers), and sent through the indication channel. Is up to the upper layer to collect messages from the indication channel.

Ex: msg <- pl.Ind

The indication channel will block if those messages aren't treated somehow. To prevent that, create a go routine that continually reads from pl.Ind

Example
peers := make(map[int]chan<- Message)
l0 := NewByChan(0, peers)
l1 := NewByChan(1, peers)
l0.Send(1, []byte("teste"))
c := l1.GetDeliver()
msg := <-c
fmt.Println(msg.Src)
fmt.Println(string(msg.Payload))
Output:

0
teste

func NewBySocket

func NewBySocket(id int, proto string, peers map[int]string) (Link, error)

NewBySocket returns a new `Socket` or an `error`. NOTE: All connections to `Peer`s are established during this function.

Example
peers := map[int]string{
	0: ":10000",
	1: ":10001",
}
l0, err := NewBySocket(0, "tcp4", peers)
if err != nil {
	log.Fatalf("Error creation l0: %v", err)
}
l1, err := NewBySocket(1, "tcp4", peers)
if err != nil {
	log.Fatalf("Error creation l1: %v", err)
}
// time.Sleep(time.Second)
err = l0.Send(1, []byte("teste"))
if err != nil {
	log.Fatalf("error sending message: %v", err)
}
c := l1.GetDeliver()
msg := <-c
fmt.Println(msg.Src)
fmt.Println(string(msg.Payload))
Output:

0
teste

type Message

type Message struct {
	Src     int
	Payload []byte
}

Message is use for indication. These messages are intended to be read by the upper layer. Src is the sender's process ID in the link pool.

Jump to

Keyboard shortcuts

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