-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
81 changed files
with
2,289 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// QUICListener e a implementacao do Listener para QUIC | ||
type QUICListener struct { | ||
listener quic.Listener | ||
} | ||
|
||
// Close fecha o QUICListener | ||
func (l *QUICListener) Close() error { | ||
return l.listener.Close() | ||
} | ||
|
||
// Accept recebe uma conexao para um dado QUICListener | ||
func (l *QUICListener) Accept(ctx context.Context) (Session, error) { | ||
session, err := l.listener.Accept(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &QUICSession{session: session}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// QUICRPC implementacao do canal de RPC para QUIC | ||
type QUICRPC struct { | ||
address string | ||
port int | ||
tlsConfig *tls.Config | ||
config *quic.Config | ||
} | ||
|
||
// Listen escuta as conexoes de entrada no QUICRPC | ||
func (q *QUICRPC) Listen() (Listener, error) { | ||
listener, err := quic.ListenAddr( | ||
fmt.Sprintf("%s:%d", q.address, q.port), | ||
q.tlsConfig, | ||
q.config, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &QUICListener{listener: listener}, nil | ||
} | ||
|
||
// Connect conecta num servidor com QUICRPC | ||
func (q *QUICRPC) Connect() (Session, error) { | ||
session, err := quic.DialAddr( | ||
fmt.Sprintf("%s:%d", q.address, q.port), | ||
q.tlsConfig, | ||
q.config, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &QUICSession{session: session}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// QUICSession e a implementacao de Session para o QUIC | ||
type QUICSession struct { | ||
session quic.Session | ||
} | ||
|
||
// RemoteAddress retorna o endereco e a porta de uma QUICSession | ||
func (qs *QUICSession) RemoteAddress() (string, int, error) { | ||
addrParts := strings.Split(qs.session.RemoteAddr().String(), ":") | ||
if len(addrParts) != 2 { | ||
return "", 0, fmt.Errorf("invalid remote address") | ||
} | ||
|
||
portInt64, err := strconv.ParseInt(addrParts[1], 10, 32) | ||
if err != nil { | ||
return "", 0, fmt.Errorf("invalid port number") | ||
} | ||
|
||
return addrParts[0], int(portInt64), nil | ||
} | ||
|
||
// AcceptStream recebe uma stream de dados de um client | ||
func (qs *QUICSession) AcceptStream(ctx context.Context) (Stream, error) { | ||
stream, err := qs.session.AcceptStream(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &QUICStream{stream: stream}, nil | ||
} | ||
|
||
// OpenStream cria uma nova stream de dados com o servidor | ||
func (qs *QUICSession) OpenStream(ctx context.Context) (Stream, error) { | ||
stream, err := qs.session.OpenStreamSync(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &QUICStream{stream: stream}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// QUICStream is a channel stream implementation for QUIC | ||
type QUICStream struct { | ||
stream quic.Stream | ||
} | ||
|
||
// Close fecha a QUICStream | ||
func (s *QUICStream) Close() error { | ||
return s.stream.Close() | ||
} | ||
|
||
// Write escreve os dados em uma QUICStream | ||
func (s *QUICStream) Write(buf []byte) (int, error) { | ||
return s.stream.Write(buf) | ||
} | ||
|
||
// Read le os dados de uma QUICStream | ||
func (s *QUICStream) Read(buf []byte) (int, error) { | ||
return s.stream.Read(buf) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package greetings | ||
|
||
// Codigo gerado pelo aRPC; NAO EDITAR! | ||
|
||
import ( | ||
"context" | ||
"github.com/almeida-raphael/arpc/controller" | ||
) | ||
|
||
type Greetings struct { | ||
controller *controller.RPC | ||
} | ||
|
||
func NewGreetings(controller *controller.RPC) Greetings { | ||
return Greetings{ | ||
controller: controller, | ||
} | ||
} | ||
|
||
func (greetings *Greetings)SayHi(SayHiRequest *SayHiRequest, ctx ...context.Context)(*SayHiResponse, error){ | ||
if ctx == nil || len(ctx) == 0 { | ||
ctx = []context.Context{context.Background()} | ||
} | ||
|
||
response := SayHiResponse{} | ||
|
||
err := greetings.controller.SendRPCCall( | ||
ctx[0], | ||
4148486943, | ||
0, | ||
SayHiRequest, | ||
&response, | ||
) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package greetings | ||
|
||
// Person e uma struct com os dados de uma pessoa | ||
type Person struct { | ||
title uint64 | ||
name text | ||
} | ||
|
||
// SayHiRequest e a struct passada como entrada do procedimento SayHi | ||
type SayHiRequest struct { | ||
person Person | ||
} | ||
|
||
// SayHiResponse e a struct passada como saida do procedimento SayHi | ||
type SayHiResponse struct { | ||
response text | ||
} | ||
|
||
// SayHi declaracao do procedimento SayHi | ||
type SayHi func(request *SayHiRequest) (*SayHiResponse, error) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package greetings | ||
|
||
// Codigo gerado pelo aRPC; NAO EDITAR! | ||
|
||
import "github.com/almeida-raphael/arpc/controller" | ||
|
||
type GreetingsServer interface { | ||
SayHi(SayHiRequest *SayHiRequest)(*SayHiResponse, error) | ||
} | ||
|
||
func bindSayHi(server GreetingsServer)( | ||
func(msg []byte)([]byte, error), | ||
) { | ||
return func(msg []byte)([]byte, error){ | ||
SayHiRequest := SayHiRequest{} | ||
err := SayHiRequest.UnmarshalBinary(msg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response, err := server.SayHi(&SayHiRequest) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
responseBytes, err := response.MarshalBinary() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return responseBytes, nil | ||
} | ||
} | ||
|
||
func RegisterGreetingsServer(controller controller.RPC, srv GreetingsServer){ | ||
controller.RegisterService( | ||
4148486943, | ||
map[uint16]func(message []byte)([]byte, error){ | ||
0: bindSayHi(srv), | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/almeida-raphael/arpc_examples/examples/greetings" | ||
"log" | ||
) | ||
|
||
func main(){ | ||
rootCAPath := os.Getenv("CA_FILE") | ||
serverAddress := os.Getenv("SERVER_ADDRESS") | ||
|
||
rootCA, err := LoadCA(rootCAPath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
tlsConfig := tls.Config{ | ||
RootCAs: rootCA, | ||
NextProtos: []string{"quic-arcp"}, | ||
} | ||
|
||
aRPCController := controller.NewRPCController( | ||
channel.NewQUICChannel( | ||
serverAddress, | ||
7653, | ||
&tlsConfig, | ||
&quic.Config{ | ||
MaxIncomingStreams: 100000, | ||
}, | ||
), | ||
) | ||
|
||
greetingsService := greetings.NewGreetings(&aRPCController) | ||
err := aRPCController.StartClient() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
hiResponse, err := greetingsService.SayHi(&requestData) | ||
|
||
// O tratamento de erros e resposta devem continuar abaixo | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Go = import "/go.capnp"; | ||
@0x85d3acc3f0f0e0f8; | ||
$Go.package("books"); | ||
$Go.import("pkg/books"); | ||
|
||
struct Book { | ||
# Titulo do livro. | ||
title @0 :Text; | ||
|
||
# Numero de paginas no livro. | ||
pageCount @1 :Int32; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
namespace java calculator | ||
namespace py calculator | ||
|
||
enum Operation { | ||
ADD = 1, | ||
SUBTRACT = 2, | ||
MULTIPLY = 3, | ||
DIVIDE = 4 | ||
} | ||
|
||
struct Work { | ||
1: i32 num1 = 0, | ||
2: i32 num2, | ||
3: Operation op, | ||
4: optional string comment, | ||
} | ||
|
||
exception InvalidOperation { | ||
1: i32 what, | ||
2: string why | ||
} | ||
|
||
service Calculator { | ||
|
||
void ping(), | ||
|
||
i32 add(1:i32 num1, 2:i32 num2), | ||
|
||
i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch), | ||
|
||
/** | ||
* Este metodo tem o modificador oneway, | ||
* que implica que o cliente apenas faz a requisicao mas | ||
* nao espera a resposta. | ||
* Metodos com oneway devem retornar void. | ||
*/ | ||
oneway void zip() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Monta uma nova mensagem vazia, alocando uma struct do Cap'n Proto. | ||
msg, seg, err := capnp.NewMessage(capnp.SingleSegment(nil)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Cria uma nova struct de Book. | ||
book, err := books.NewRootBook(seg) | ||
if err != nil { | ||
panic(err) | ||
} | ||
book.SetTitle("Ready Player One") | ||
book.SetPageCount(389) | ||
|
||
// Escreve a mensagem para a saida padrao. | ||
err = capnp.NewEncoder(os.Stdout).Encode(msg) | ||
if err != nil { | ||
panic(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
// Course e o campo de golf onde o jogo acontece | ||
type course struct { | ||
ID uint64 | ||
name text | ||
holes []hole | ||
image binary | ||
tags []text | ||
} | ||
|
||
type hole struct { | ||
// Lat e a latitude do buraco. | ||
lat float64 | ||
// Lon e a longitude do buraco. | ||
lon float64 | ||
// Par e o indice de dificulade. | ||
par uint8 | ||
// Water indica a presenca de agua. | ||
water bool | ||
// Sand indica a presenca de areia. | ||
sand bool | ||
} |
Oops, something went wrong.