# 容錯計算 # gRPC (使用golang) ### Protocol Buffers 撰寫和編譯 需要撰寫一個以proto為副檔名的檔案,裡面定義server提供的api,和相關的交換參數。接下來編譯後會產生_grpc.pb.go和pb.go,這些檔案能讓proto定義的api和server client實際實作的function溝通。  新專案需要在grpc資料夾下?不然無法import required and optional is removed in Protocol Buffers 3. https://stackoverflow.com/questions/31801257/why-required-and-optional-is-removed-in-protocol-buffers-3 repeated: https://hoohoo.top/blog/golang-grpc-uses-repeated-to-return-multiple-strokes-of-data/ 編譯參數: https://zhuanlan.zhihu.com/p/512889392 https://itnext.io/build-grpc-server-with-golang-go-step-by-step-b3f5abcf9e0e ### 創一個新golang gRPC專案 1.mkdir(創一個專案資料夾) 2.cd道專案資料夾 go mod init <專案名稱> 這樣就能使用自己定義的package了 3.install grpc-go package go get -u google.golang.org/grpc 4.code <專案資料夾> 這樣vscode應該就不會抓不到檔案 5.在import package時,如果是自己寫的package,那前面是專案名稱,後面才是package  參考資料: https://itnext.io/build-grpc-server-with-golang-go-step-by-step-b3f5abcf9e0e 編譯proto(先進到proto檔案所在資料夾) protoc --go_out=. --go_opt=paths=source_relative \ --go-grpc_out=. --go-grpc_opt=paths=source_relative \ *.proto proto2下載: https://gist.github.com/ddupg/08118b42376eab110f811c7f4522547e 編譯proto (proto2): protoc --go_out=. --go-grpc_out=. *.proto proto2 和proto3 差異: https://www.cnblogs.com/yuzyong/p/15380553.html 問題解決:  Go的語法相關問題: unknown field in struct literal: https://stackoverflow.com/questions/37780520/unknown-field-in-struct-literal ### 作業還沒完成部分 1.server ip設定和網路問題 2.register voter需要用檔案來記錄,這樣就不用每次都重新輸入 3.challenge 4.election 5.vote ### challenge response 796t.com/content/1514290805.html # Part2 加入驗證和簽名 public_key使用libsodium libsodium:https://doc.libsodium.org/ go的版本(Sodium): github:https://github.com/jamesruan/sodium documents:https://pkg.go.dev/github.com/jamesruan/sodium 使用go get 引入需要的module go get github.com/jamesruan/sodium 這樣sodium就會加到mod中 server 該回傳沒有回傳會報error,
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up