@blinklabs/dingo 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/.dingo/blob/000001.sst +0 -0
  2. package/.dingo/blob/000001.vlog +0 -0
  3. package/.dingo/blob/DISCARD +0 -0
  4. package/.dingo/blob/KEYREGISTRY +2 -0
  5. package/.dingo/blob/MANIFEST +0 -0
  6. package/.dingo/metadata.sqlite +0 -0
  7. package/.github/workflows/golangci-lint.yml +1 -1
  8. package/.github/workflows/publish.yml +1 -7
  9. package/README.md +2 -1
  10. package/{dist/dingo_darwin_amd64_v1/dingo → dingo} +0 -0
  11. package/dingo.yaml.example +53 -0
  12. package/package.json +5 -5
  13. package/Dockerfile +0 -25
  14. package/Makefile +0 -53
  15. package/blockfetch.go +0 -144
  16. package/chain/chain.go +0 -504
  17. package/chain/chain_test.go +0 -468
  18. package/chain/errors.go +0 -80
  19. package/chain/event.go +0 -33
  20. package/chain/iter.go +0 -64
  21. package/chainsync/chainsync.go +0 -97
  22. package/chainsync.go +0 -223
  23. package/cmd/dingo/load.go +0 -52
  24. package/cmd/dingo/main.go +0 -118
  25. package/cmd/dingo/serve.go +0 -49
  26. package/config/cardano/node.go +0 -192
  27. package/config/cardano/node_test.go +0 -85
  28. package/config/cardano/preview/README.md +0 -4
  29. package/config/cardano/preview/alonzo-genesis.json +0 -196
  30. package/config/cardano/preview/byron-genesis.json +0 -117
  31. package/config/cardano/preview/config.json +0 -114
  32. package/config/cardano/preview/conway-genesis.json +0 -297
  33. package/config/cardano/preview/shelley-genesis.json +0 -68
  34. package/config.go +0 -245
  35. package/connmanager/connection_manager.go +0 -105
  36. package/connmanager/connection_manager_test.go +0 -185
  37. package/connmanager/event.go +0 -37
  38. package/connmanager/listener.go +0 -140
  39. package/connmanager/outbound.go +0 -93
  40. package/connmanager/socket.go +0 -55
  41. package/connmanager/unix.go +0 -78
  42. package/custom-p2p-topology.json +0 -24
  43. package/custom-p2p-topology.json.backup +0 -24
  44. package/custom-p2p-topology.json.mainnet +0 -37
  45. package/database/account.go +0 -138
  46. package/database/block.go +0 -362
  47. package/database/certs.go +0 -53
  48. package/database/commit_timestamp.go +0 -77
  49. package/database/database.go +0 -118
  50. package/database/database_test.go +0 -62
  51. package/database/drep.go +0 -27
  52. package/database/epoch.go +0 -121
  53. package/database/immutable/chunk.go +0 -182
  54. package/database/immutable/immutable.go +0 -350
  55. package/database/immutable/immutable_test.go +0 -59
  56. package/database/immutable/primary.go +0 -106
  57. package/database/immutable/secondary.go +0 -103
  58. package/database/immutable/testdata/08893.chunk +0 -0
  59. package/database/immutable/testdata/08893.primary +0 -0
  60. package/database/immutable/testdata/08893.secondary +0 -0
  61. package/database/immutable/testdata/08894.chunk +0 -0
  62. package/database/immutable/testdata/08894.primary +0 -0
  63. package/database/immutable/testdata/08894.secondary +0 -0
  64. package/database/immutable/testdata/README.md +0 -4
  65. package/database/plugin/blob/badger/commit_timestamp.go +0 -50
  66. package/database/plugin/blob/badger/database.go +0 -152
  67. package/database/plugin/blob/badger/logger.go +0 -63
  68. package/database/plugin/blob/badger/metrics.go +0 -98
  69. package/database/plugin/blob/blob.go +0 -19
  70. package/database/plugin/blob/store.go +0 -40
  71. package/database/plugin/log.go +0 -27
  72. package/database/plugin/metadata/metadata.go +0 -19
  73. package/database/plugin/metadata/sqlite/account.go +0 -224
  74. package/database/plugin/metadata/sqlite/certs.go +0 -58
  75. package/database/plugin/metadata/sqlite/commit_timestamp.go +0 -68
  76. package/database/plugin/metadata/sqlite/database.go +0 -218
  77. package/database/plugin/metadata/sqlite/epoch.go +0 -120
  78. package/database/plugin/metadata/sqlite/models/account.go +0 -81
  79. package/database/plugin/metadata/sqlite/models/auth_committee_hot.go +0 -26
  80. package/database/plugin/metadata/sqlite/models/deregistration_drep.go +0 -26
  81. package/database/plugin/metadata/sqlite/models/drep.go +0 -27
  82. package/database/plugin/metadata/sqlite/models/epoch.go +0 -31
  83. package/database/plugin/metadata/sqlite/models/models.go +0 -45
  84. package/database/plugin/metadata/sqlite/models/pool.go +0 -97
  85. package/database/plugin/metadata/sqlite/models/pparam_update.go +0 -27
  86. package/database/plugin/metadata/sqlite/models/pparams.go +0 -27
  87. package/database/plugin/metadata/sqlite/models/registration_drep.go +0 -28
  88. package/database/plugin/metadata/sqlite/models/resign_committee_cold.go +0 -27
  89. package/database/plugin/metadata/sqlite/models/stake_registration_delegation.go +0 -27
  90. package/database/plugin/metadata/sqlite/models/stake_vote_delegation.go +0 -27
  91. package/database/plugin/metadata/sqlite/models/stake_vote_registration_delegation.go +0 -27
  92. package/database/plugin/metadata/sqlite/models/tip.go +0 -26
  93. package/database/plugin/metadata/sqlite/models/update_drep.go +0 -27
  94. package/database/plugin/metadata/sqlite/models/utxo.go +0 -30
  95. package/database/plugin/metadata/sqlite/models/vote_delegation.go +0 -26
  96. package/database/plugin/metadata/sqlite/models/vote_registration_delegation.go +0 -26
  97. package/database/plugin/metadata/sqlite/pool.go +0 -240
  98. package/database/plugin/metadata/sqlite/pparams.go +0 -110
  99. package/database/plugin/metadata/sqlite/tip.go +0 -83
  100. package/database/plugin/metadata/sqlite/utxo.go +0 -292
  101. package/database/plugin/metadata/store.go +0 -168
  102. package/database/plugin/option.go +0 -190
  103. package/database/plugin/plugin.go +0 -20
  104. package/database/plugin/register.go +0 -118
  105. package/database/pparams.go +0 -145
  106. package/database/tip.go +0 -45
  107. package/database/txn.go +0 -147
  108. package/database/types/types.go +0 -74
  109. package/database/types/types_test.go +0 -83
  110. package/database/utxo.go +0 -263
  111. package/dist/artifacts.json +0 -1
  112. package/dist/checksums.txt +0 -22
  113. package/dist/config.yaml +0 -253
  114. package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz +0 -0
  115. package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz.sbom.json +0 -1
  116. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz +0 -0
  117. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz.sbom.json +0 -1
  118. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz +0 -0
  119. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz.sbom.json +0 -1
  120. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk +0 -0
  121. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk.sbom.json +0 -1
  122. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb +0 -0
  123. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb.sbom.json +0 -1
  124. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm +0 -0
  125. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm.sbom.json +0 -1
  126. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk +0 -0
  127. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk.sbom.json +0 -1
  128. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb +0 -0
  129. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb.sbom.json +0 -1
  130. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm +0 -0
  131. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm.sbom.json +0 -1
  132. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz +0 -0
  133. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz.sbom.json +0 -1
  134. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz +0 -0
  135. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz.sbom.json +0 -1
  136. package/dist/dingo_darwin_arm64_v8.0/dingo +0 -0
  137. package/dist/dingo_linux_amd64_v1/dingo +0 -0
  138. package/dist/dingo_linux_arm64_v8.0/dingo +0 -0
  139. package/dist/homebrew/dingo.rb +0 -51
  140. package/dist/metadata.json +0 -1
  141. package/event/event.go +0 -141
  142. package/event/event_test.go +0 -115
  143. package/event/metrics.go +0 -44
  144. package/go.mod +0 -98
  145. package/go.sum +0 -358
  146. package/internal/config/config.go +0 -145
  147. package/internal/config/config_test.go +0 -118
  148. package/internal/node/load.go +0 -149
  149. package/internal/node/node.go +0 -176
  150. package/internal/version/version.go +0 -33
  151. package/ledger/certs.go +0 -113
  152. package/ledger/chainsync.go +0 -578
  153. package/ledger/eras/allegra.go +0 -154
  154. package/ledger/eras/alonzo.go +0 -156
  155. package/ledger/eras/babbage.go +0 -154
  156. package/ledger/eras/byron.go +0 -42
  157. package/ledger/eras/conway.go +0 -158
  158. package/ledger/eras/eras.go +0 -44
  159. package/ledger/eras/mary.go +0 -154
  160. package/ledger/eras/shelley.go +0 -164
  161. package/ledger/error.go +0 -19
  162. package/ledger/event.go +0 -50
  163. package/ledger/metrics.go +0 -53
  164. package/ledger/queries.go +0 -260
  165. package/ledger/slot.go +0 -127
  166. package/ledger/slot_test.go +0 -147
  167. package/ledger/state.go +0 -726
  168. package/ledger/view.go +0 -73
  169. package/localstatequery.go +0 -50
  170. package/localtxmonitor.go +0 -44
  171. package/localtxsubmission.go +0 -52
  172. package/mempool/consumer.go +0 -98
  173. package/mempool/mempool.go +0 -322
  174. package/node.go +0 -320
  175. package/peergov/event.go +0 -27
  176. package/peergov/peer.go +0 -67
  177. package/peergov/peergov.go +0 -290
  178. package/peersharing.go +0 -70
  179. package/preview-local-topology.json +0 -23
  180. package/topology/topology.go +0 -69
  181. package/topology/topology_test.go +0 -179
  182. package/tracing.go +0 -65
  183. package/txsubmission.go +0 -233
  184. package/utxorpc/query.go +0 -311
  185. package/utxorpc/submit.go +0 -395
  186. package/utxorpc/sync.go +0 -276
  187. package/utxorpc/utxorpc.go +0 -166
  188. package/utxorpc/watch.go +0 -310
@@ -1,105 +0,0 @@
1
- // Copyright 2024 Blink Labs Software
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- package connmanager
16
-
17
- import (
18
- "io"
19
- "log/slog"
20
- "sync"
21
-
22
- "github.com/blinklabs-io/dingo/event"
23
- ouroboros "github.com/blinklabs-io/gouroboros"
24
- )
25
-
26
- // ConnectionManagerConnClosedFunc is a function that takes a connection ID and an optional error
27
- type ConnectionManagerConnClosedFunc func(ouroboros.ConnectionId, error)
28
-
29
- type ConnectionManager struct {
30
- config ConnectionManagerConfig
31
- connections map[ouroboros.ConnectionId]*ouroboros.Connection
32
- connectionsMutex sync.Mutex
33
- }
34
-
35
- type ConnectionManagerConfig struct {
36
- Logger *slog.Logger
37
- EventBus *event.EventBus
38
- ConnClosedFunc ConnectionManagerConnClosedFunc
39
- Listeners []ListenerConfig
40
- OutboundConnOpts []ouroboros.ConnectionOptionFunc
41
- OutboundSourcePort uint
42
- }
43
-
44
- func NewConnectionManager(cfg ConnectionManagerConfig) *ConnectionManager {
45
- if cfg.Logger == nil {
46
- cfg.Logger = slog.New(slog.NewJSONHandler(io.Discard, nil))
47
- }
48
- cfg.Logger = cfg.Logger.With("component", "connmanager")
49
- return &ConnectionManager{
50
- config: cfg,
51
- connections: make(
52
- map[ouroboros.ConnectionId]*ouroboros.Connection,
53
- ),
54
- }
55
- }
56
-
57
- func (c *ConnectionManager) Start() error {
58
- if err := c.startListeners(); err != nil {
59
- return err
60
- }
61
- return nil
62
- }
63
-
64
- func (c *ConnectionManager) AddConnection(conn *ouroboros.Connection) {
65
- connId := conn.Id()
66
- c.connectionsMutex.Lock()
67
- c.connections[connId] = conn
68
- c.connectionsMutex.Unlock()
69
- go func() {
70
- err := <-conn.ErrorChan()
71
- // Remove connection
72
- c.RemoveConnection(connId)
73
- // Generate event
74
- if c.config.EventBus != nil {
75
- c.config.EventBus.Publish(
76
- ConnectionClosedEventType,
77
- event.NewEvent(
78
- ConnectionClosedEventType,
79
- ConnectionClosedEvent{
80
- ConnectionId: connId,
81
- Error: err,
82
- },
83
- ),
84
- )
85
- }
86
- // Call configured connection closed callback func
87
- if c.config.ConnClosedFunc != nil {
88
- c.config.ConnClosedFunc(connId, err)
89
- }
90
- }()
91
- }
92
-
93
- func (c *ConnectionManager) RemoveConnection(connId ouroboros.ConnectionId) {
94
- c.connectionsMutex.Lock()
95
- delete(c.connections, connId)
96
- c.connectionsMutex.Unlock()
97
- }
98
-
99
- func (c *ConnectionManager) GetConnectionById(
100
- connId ouroboros.ConnectionId,
101
- ) *ouroboros.Connection {
102
- c.connectionsMutex.Lock()
103
- defer c.connectionsMutex.Unlock()
104
- return c.connections[connId]
105
- }
@@ -1,185 +0,0 @@
1
- // Copyright 2025 Blink Labs Software
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- package connmanager_test
16
-
17
- import (
18
- "errors"
19
- "io"
20
- "testing"
21
- "time"
22
-
23
- "github.com/blinklabs-io/dingo/connmanager"
24
-
25
- ouroboros "github.com/blinklabs-io/gouroboros"
26
- "github.com/blinklabs-io/gouroboros/protocol/keepalive"
27
- ouroboros_mock "github.com/blinklabs-io/ouroboros-mock"
28
- "go.uber.org/goleak"
29
- )
30
-
31
- /*
32
- func TestConnectionManagerTagString(t *testing.T) {
33
- testDefs := map[connmanager.ConnectionManagerTag]string{
34
- connmanager.ConnectionManagerTagHostP2PLedger: "HostP2PLedger",
35
- connmanager.ConnectionManagerTagHostP2PGossip: "HostP2PGossip",
36
- connmanager.ConnectionManagerTagRoleInitiator: "RoleInitiator",
37
- connmanager.ConnectionManagerTagRoleResponder: "RoleResponder",
38
- connmanager.ConnectionManagerTagNone: "Unknown",
39
- connmanager.ConnectionManagerTag(9999): "Unknown",
40
- }
41
- for k, v := range testDefs {
42
- if k.String() != v {
43
- t.Fatalf(
44
- "did not get expected string for ID %d: got %s, expected %s",
45
- k,
46
- k.String(),
47
- v,
48
- )
49
- }
50
- }
51
- }
52
- */
53
-
54
- func TestConnectionManagerConnError(t *testing.T) {
55
- defer goleak.VerifyNone(t)
56
- var expectedConnId ouroboros.ConnectionId
57
- expectedErr := io.EOF
58
- doneChan := make(chan any)
59
- connManager := connmanager.NewConnectionManager(
60
- connmanager.ConnectionManagerConfig{
61
- ConnClosedFunc: func(connId ouroboros.ConnectionId, err error) {
62
- if err != nil {
63
- if connId != expectedConnId {
64
- t.Fatalf(
65
- "did not receive error from expected connection: got %d, wanted %d",
66
- connId,
67
- expectedConnId,
68
- )
69
- }
70
- if !errors.Is(err, expectedErr) {
71
- t.Fatalf(
72
- "did not receive expected error: got: %s, expected: %s",
73
- err,
74
- expectedErr,
75
- )
76
- }
77
- close(doneChan)
78
- }
79
- },
80
- },
81
- )
82
- testIdx := 2
83
- var connIds []ouroboros.ConnectionId
84
- for i := 0; i < 3; i++ {
85
- mockConversation := ouroboros_mock.ConversationKeepAlive
86
- if i == testIdx {
87
- mockConversation = ouroboros_mock.ConversationKeepAliveClose
88
- }
89
- mockConn := ouroboros_mock.NewConnection(
90
- ouroboros_mock.ProtocolRoleClient,
91
- mockConversation,
92
- )
93
- oConn, err := ouroboros.New(
94
- ouroboros.WithConnection(mockConn),
95
- ouroboros.WithNetworkMagic(ouroboros_mock.MockNetworkMagic),
96
- ouroboros.WithNodeToNode(true),
97
- ouroboros.WithKeepAlive(true),
98
- ouroboros.WithKeepAliveConfig(
99
- keepalive.NewConfig(
100
- keepalive.WithCookie(ouroboros_mock.MockKeepAliveCookie),
101
- keepalive.WithPeriod(2*time.Second),
102
- keepalive.WithTimeout(1*time.Second),
103
- ),
104
- ),
105
- )
106
- if err != nil {
107
- t.Fatalf("unexpected error when creating Ouroboros object: %s", err)
108
- }
109
- if i == testIdx {
110
- expectedConnId = oConn.Id()
111
- }
112
- connManager.AddConnection(oConn)
113
- connIds = append(connIds, oConn.Id())
114
- }
115
- select {
116
- case <-doneChan:
117
- // Shutdown other connections
118
- for _, connId := range connIds {
119
- if connId != expectedConnId {
120
- tmpConn := connManager.GetConnectionById(connId)
121
- tmpConn.Close()
122
- }
123
- }
124
- // TODO: actually wait for shutdown
125
- time.Sleep(5 * time.Second)
126
- return
127
- case <-time.After(10 * time.Second):
128
- t.Fatalf("did not receive error within timeout")
129
- }
130
- }
131
-
132
- func TestConnectionManagerConnClosed(t *testing.T) {
133
- defer goleak.VerifyNone(t)
134
- var expectedConnId ouroboros.ConnectionId
135
- doneChan := make(chan any)
136
- connManager := connmanager.NewConnectionManager(
137
- connmanager.ConnectionManagerConfig{
138
- ConnClosedFunc: func(connId ouroboros.ConnectionId, err error) {
139
- if connId != expectedConnId {
140
- t.Fatalf(
141
- "did not receive closed signal from expected connection: got %d, wanted %d",
142
- connId,
143
- expectedConnId,
144
- )
145
- }
146
- if err != nil {
147
- t.Fatalf("received unexpected error: %s", err)
148
- }
149
- close(doneChan)
150
- },
151
- },
152
- )
153
- mockConn := ouroboros_mock.NewConnection(
154
- ouroboros_mock.ProtocolRoleClient,
155
- []ouroboros_mock.ConversationEntry{
156
- ouroboros_mock.ConversationEntryHandshakeRequestGeneric,
157
- ouroboros_mock.ConversationEntryHandshakeNtNResponse,
158
- },
159
- )
160
- oConn, err := ouroboros.New(
161
- ouroboros.WithConnection(mockConn),
162
- ouroboros.WithNetworkMagic(ouroboros_mock.MockNetworkMagic),
163
- ouroboros.WithNodeToNode(true),
164
- ouroboros.WithKeepAlive(false),
165
- )
166
- if err != nil {
167
- t.Fatalf("unexpected error when creating Ouroboros object: %s", err)
168
- }
169
- expectedConnId = oConn.Id()
170
- connManager.AddConnection(oConn)
171
- time.AfterFunc(
172
- 1*time.Second,
173
- func() {
174
- oConn.Close()
175
- },
176
- )
177
- select {
178
- case <-doneChan:
179
- // TODO: actually wait for shutdown
180
- time.Sleep(5 * time.Second)
181
- return
182
- case <-time.After(10 * time.Second):
183
- t.Fatalf("did not receive error within timeout")
184
- }
185
- }
@@ -1,37 +0,0 @@
1
- // Copyright 2024 Blink Labs Software
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- package connmanager
16
-
17
- import (
18
- "net"
19
-
20
- ouroboros "github.com/blinklabs-io/gouroboros"
21
- )
22
-
23
- const (
24
- InboundConnectionEventType = "connmanager.inbound-conn"
25
- ConnectionClosedEventType = "connmanager.conn-closed"
26
- )
27
-
28
- type InboundConnectionEvent struct {
29
- ConnectionId ouroboros.ConnectionId
30
- LocalAddr net.Addr
31
- RemoteAddr net.Addr
32
- }
33
-
34
- type ConnectionClosedEvent struct {
35
- ConnectionId ouroboros.ConnectionId
36
- Error error
37
- }
@@ -1,140 +0,0 @@
1
- // Copyright 2025 Blink Labs Software
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- package connmanager
16
-
17
- import (
18
- "context"
19
- "fmt"
20
- "net"
21
-
22
- "github.com/blinklabs-io/dingo/event"
23
- ouroboros "github.com/blinklabs-io/gouroboros"
24
- )
25
-
26
- type ListenerConfig struct {
27
- UseNtC bool
28
- Listener net.Listener
29
- ListenNetwork string
30
- ListenAddress string
31
- ReuseAddress bool
32
- ConnectionOpts []ouroboros.ConnectionOptionFunc
33
- }
34
-
35
- func (c *ConnectionManager) startListeners() error {
36
- for _, l := range c.config.Listeners {
37
- if err := c.startListener(l); err != nil {
38
- return err
39
- }
40
- }
41
- return nil
42
- }
43
-
44
- func (c *ConnectionManager) startListener(l ListenerConfig) error {
45
- // Create listener if none is provided
46
- if l.Listener == nil {
47
- listenConfig := net.ListenConfig{}
48
- if l.ReuseAddress {
49
- listenConfig.Control = socketControl
50
- }
51
- listener, err := listenConfig.Listen(
52
- context.Background(),
53
- l.ListenNetwork,
54
- l.ListenAddress,
55
- )
56
- if err != nil {
57
- return fmt.Errorf("failed to open listening socket: %w", err)
58
- }
59
- l.Listener = listener
60
- if l.UseNtC {
61
- c.config.Logger.Info(
62
- "listening for ouroboros node-to-client connections on " + l.ListenAddress,
63
- )
64
- } else {
65
- c.config.Logger.Info(
66
- "listening for ouroboros node-to-node connections on " + l.ListenAddress,
67
- )
68
- }
69
- }
70
- // Build connection options
71
- defaultConnOpts := []ouroboros.ConnectionOptionFunc{
72
- ouroboros.WithLogger(c.config.Logger),
73
- ouroboros.WithNodeToNode(!l.UseNtC),
74
- ouroboros.WithServer(true),
75
- }
76
- defaultConnOpts = append(
77
- defaultConnOpts,
78
- l.ConnectionOpts...,
79
- )
80
- go func() {
81
- for {
82
- // Accept connection
83
- conn, err := l.Listener.Accept()
84
- if err != nil {
85
- c.config.Logger.Error(
86
- fmt.Sprintf("listener: accept failed: %s", err),
87
- )
88
- continue
89
- }
90
- // Wrap UNIX connections
91
- if uConn, ok := conn.(*net.UnixConn); ok {
92
- tmpConn, err := NewUnixConn(uConn)
93
- if err != nil {
94
- c.config.Logger.Error(
95
- fmt.Sprintf("listener: accept failed: %s", err),
96
- )
97
- _ = conn.Close()
98
- continue
99
- }
100
- conn = tmpConn
101
- }
102
- c.config.Logger.Info(
103
- fmt.Sprintf(
104
- "listener: accepted connection from %s",
105
- conn.RemoteAddr(),
106
- ),
107
- )
108
- // Setup Ouroboros connection
109
- connOpts := append(
110
- defaultConnOpts,
111
- ouroboros.WithConnection(conn),
112
- )
113
- oConn, err := ouroboros.NewConnection(connOpts...)
114
- if err != nil {
115
- c.config.Logger.Error(
116
- fmt.Sprintf(
117
- "listener: failed to setup connection: %s",
118
- err,
119
- ),
120
- )
121
- continue
122
- }
123
- // Add to connection manager
124
- c.AddConnection(oConn)
125
- // Generate event
126
- c.config.EventBus.Publish(
127
- InboundConnectionEventType,
128
- event.NewEvent(
129
- InboundConnectionEventType,
130
- InboundConnectionEvent{
131
- ConnectionId: oConn.Id(),
132
- LocalAddr: conn.LocalAddr(),
133
- RemoteAddr: conn.RemoteAddr(),
134
- },
135
- ),
136
- )
137
- }
138
- }()
139
- return nil
140
- }
@@ -1,93 +0,0 @@
1
- // Copyright 2024 Blink Labs Software
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- package connmanager
16
-
17
- import (
18
- "context"
19
- "fmt"
20
- "net"
21
- "time"
22
-
23
- ouroboros "github.com/blinklabs-io/gouroboros"
24
- "go.opentelemetry.io/otel"
25
- "go.opentelemetry.io/otel/attribute"
26
- )
27
-
28
- func (c *ConnectionManager) CreateOutboundConn(
29
- address string,
30
- ) (*ouroboros.Connection, error) {
31
- t := otel.Tracer("")
32
- if t != nil {
33
- _, span := t.Start(context.TODO(), "create outbound connection")
34
- defer span.End()
35
- span.SetAttributes(
36
- attribute.String("peer.address", address),
37
- )
38
- }
39
-
40
- var clientAddr net.Addr
41
- dialer := net.Dialer{
42
- Timeout: 10 * time.Second,
43
- }
44
- if c.config.OutboundSourcePort > 0 {
45
- // Setup connection to use our listening port as the source port
46
- // This is required for peer sharing to be useful
47
- clientAddr, _ = net.ResolveTCPAddr(
48
- "tcp",
49
- fmt.Sprintf(":%d", c.config.OutboundSourcePort),
50
- )
51
- dialer.LocalAddr = clientAddr
52
- dialer.Control = socketControl
53
- }
54
- c.config.Logger.Debug(
55
- "establishing TCP connection to: "+address,
56
- "role", "client",
57
- )
58
- tmpConn, err := dialer.Dial("tcp", address)
59
- if err != nil {
60
- return nil, err
61
- }
62
- // Build connection options
63
- connOpts := []ouroboros.ConnectionOptionFunc{
64
- ouroboros.WithConnection(tmpConn),
65
- ouroboros.WithLogger(c.config.Logger),
66
- }
67
- connOpts = append(
68
- connOpts,
69
- c.config.OutboundConnOpts...,
70
- )
71
- // Setup Ouroboros connection
72
- c.config.Logger.Debug(
73
- "establishing ouroboros protocol to "+address,
74
- "role", "client",
75
- )
76
- oConn, err := ouroboros.NewConnection(
77
- connOpts...,
78
- )
79
- if err != nil {
80
- return nil, err
81
- }
82
- c.config.Logger.Info(
83
- "connected ouroboros to "+address,
84
- "role", "client",
85
- )
86
- c.config.Logger.Debug(
87
- "peer address mapping: address: "+address,
88
- "role", "client",
89
- "connection_id", oConn.Id().String(),
90
- )
91
- c.AddConnection(oConn)
92
- return oConn, nil
93
- }
@@ -1,55 +0,0 @@
1
- // Copyright 2024 Blink Labs Software
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- package connmanager
16
-
17
- import (
18
- "syscall"
19
-
20
- "golang.org/x/sys/unix"
21
- )
22
-
23
- // socketControl is a helper function for setting socket options on outbound and listener sockets
24
- func socketControl(network, address string, c syscall.RawConn) error {
25
- var innerErr error
26
- err := c.Control(func(fd uintptr) {
27
- err := unix.SetsockoptInt(
28
- int(fd),
29
- unix.SOL_SOCKET,
30
- unix.SO_REUSEADDR,
31
- 1,
32
- )
33
- if err != nil {
34
- innerErr = err
35
- return
36
- }
37
- err = unix.SetsockoptInt(
38
- int(fd),
39
- unix.SOL_SOCKET,
40
- unix.SO_REUSEPORT,
41
- 1,
42
- )
43
- if err != nil {
44
- innerErr = err
45
- return
46
- }
47
- })
48
- if innerErr != nil {
49
- return innerErr
50
- }
51
- if err != nil {
52
- return err
53
- }
54
- return nil
55
- }
@@ -1,78 +0,0 @@
1
- // Copyright 2025 Blink Labs Software
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- package connmanager
16
-
17
- import (
18
- "errors"
19
- "fmt"
20
- "net"
21
- )
22
-
23
- // UnixConn is a wrapper around net.UnixConn that provides a unique remote address
24
- type UnixConn struct {
25
- *net.UnixConn
26
- remoteAddr UnixConnAddr
27
- }
28
-
29
- func NewUnixConn(conn net.Conn) (*UnixConn, error) {
30
- uConn, ok := conn.(*net.UnixConn)
31
- if !ok {
32
- return nil, errors.New("connection is not net.UnixConn")
33
- }
34
- // Construct address string
35
- var fdNum int
36
- // Get raw connection
37
- rawConn, err := uConn.SyscallConn()
38
- if err != nil {
39
- return nil, fmt.Errorf("failed to get raw connection: %w", err)
40
- }
41
- // Retrieve socket file descriptor
42
- if rawConn == nil {
43
- return nil, errors.New("raw connection returned empty")
44
- }
45
- err = rawConn.Control(
46
- func(fd uintptr) {
47
- fdNum = int(fd)
48
- },
49
- )
50
- if err != nil {
51
- return nil, fmt.Errorf("failed to get socket file descriptor: %w", err)
52
- }
53
- return &UnixConn{
54
- UnixConn: uConn,
55
- remoteAddr: UnixConnAddr{
56
- addr: fmt.Sprintf(
57
- "unix@%d",
58
- fdNum,
59
- ),
60
- },
61
- }, nil
62
- }
63
-
64
- func (u UnixConn) RemoteAddr() net.Addr {
65
- return u.remoteAddr
66
- }
67
-
68
- type UnixConnAddr struct {
69
- addr string
70
- }
71
-
72
- func (UnixConnAddr) Network() string {
73
- return "unix"
74
- }
75
-
76
- func (u UnixConnAddr) String() string {
77
- return u.addr
78
- }