Skip to content

Commit a970d0f

Browse files
committed
Implement basics for peer protocol
1 parent 5ed0803 commit a970d0f

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

peer/server.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,48 @@ func handleConnection(conn net.Conn) {
3333
fmt.Println("Client disconnected")
3434
return
3535
}
36-
// TODO Handle error (return OR continue)
36+
continue
37+
}
38+
39+
responseData := map[string]any{}
40+
41+
requestedBlobsValue, hasRequestedBlobs := data["requested_blobs"]
42+
if hasRequestedBlobs {
43+
responseData["available_blobs"] = getAvailableBlobs(requestedBlobsValue.([]string))
44+
}
45+
46+
blobDataPaymentRateValue, hasBlobDataPaymentRate := data["blob_data_payment_rate"]
47+
if hasBlobDataPaymentRate {
48+
responseData["blob_data_payment_rate"] = getBlobDataPaymentRate(blobDataPaymentRateValue.(float64))
49+
}
50+
51+
var incomingBlob map[string]any
52+
var blobData []byte
53+
54+
requestedBlobValue, hasRequestedBlob := data["requested_blob"]
55+
if hasRequestedBlob {
56+
incomingBlob, blobData = getRequestedBlob(requestedBlobValue.(string))
57+
responseData["incoming_blob"] = incomingBlob
3758
}
3859

39-
fmt.Printf("%+v\n", data)
40-
jsonEncoder.Encode(map[string]any{})
60+
jsonEncoder.Encode(responseData)
61+
if blobData != nil {
62+
conn.Write(blobData)
63+
}
4164
}
4265
}
66+
67+
func getAvailableBlobs(requestedBlobs []string) []string {
68+
// TODO
69+
return []string{}
70+
}
71+
72+
func getBlobDataPaymentRate(blobDataPaymentRate float64) string {
73+
// TODO
74+
return "RATE_UNSET"
75+
}
76+
77+
func getRequestedBlob(requestedBlob string) (map[string]any, []byte) {
78+
// TODO
79+
return map[string]any{}, []byte{}
80+
}

reflector/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func handleConnection(conn net.Conn) {
3030
var data map[string]any
3131

3232
err := jsonDecoder.Decode(&data)
33-
3433
if err != nil {
3534
if err == io.EOF {
3635
fmt.Println("Client disconnected")

0 commit comments

Comments
 (0)