@blinklabs/dingo 0.7.0 → 0.8.1

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 (192) hide show
  1. package/README.md +2 -1
  2. package/{bin/dingo → dingo} +0 -0
  3. package/dingo.yaml.example +53 -0
  4. package/package.json +2 -2
  5. package/.github/CODEOWNERS +0 -5
  6. package/.github/assets/dingo-ate-my-blockchain.png +0 -0
  7. package/.github/assets/dingo-illustration.png +0 -0
  8. package/.github/assets/dingo-logo-with-text-horizontal.png +0 -0
  9. package/.github/assets/dingo-logo-with-text.png +0 -0
  10. package/.github/dependabot.yml +0 -19
  11. package/.github/dingo-20241210.png +0 -0
  12. package/.github/dingo.md +0 -56
  13. package/.github/workflows/ci-docker.yml +0 -36
  14. package/.github/workflows/conventional-commits.yml +0 -17
  15. package/.github/workflows/go-test.yml +0 -29
  16. package/.github/workflows/golangci-lint.yml +0 -23
  17. package/.github/workflows/publish.yml +0 -207
  18. package/Dockerfile +0 -25
  19. package/Makefile +0 -53
  20. package/blockfetch.go +0 -144
  21. package/chain/chain.go +0 -504
  22. package/chain/chain_test.go +0 -468
  23. package/chain/errors.go +0 -80
  24. package/chain/event.go +0 -33
  25. package/chain/iter.go +0 -64
  26. package/chainsync/chainsync.go +0 -97
  27. package/chainsync.go +0 -223
  28. package/cmd/dingo/load.go +0 -52
  29. package/cmd/dingo/main.go +0 -118
  30. package/cmd/dingo/serve.go +0 -49
  31. package/config/cardano/node.go +0 -192
  32. package/config/cardano/node_test.go +0 -85
  33. package/config/cardano/preview/README.md +0 -4
  34. package/config/cardano/preview/alonzo-genesis.json +0 -196
  35. package/config/cardano/preview/byron-genesis.json +0 -117
  36. package/config/cardano/preview/config.json +0 -114
  37. package/config/cardano/preview/conway-genesis.json +0 -297
  38. package/config/cardano/preview/shelley-genesis.json +0 -68
  39. package/config.go +0 -245
  40. package/connmanager/connection_manager.go +0 -105
  41. package/connmanager/connection_manager_test.go +0 -185
  42. package/connmanager/event.go +0 -37
  43. package/connmanager/listener.go +0 -140
  44. package/connmanager/outbound.go +0 -93
  45. package/connmanager/socket.go +0 -55
  46. package/connmanager/unix.go +0 -78
  47. package/custom-p2p-topology.json +0 -24
  48. package/custom-p2p-topology.json.backup +0 -24
  49. package/custom-p2p-topology.json.mainnet +0 -37
  50. package/database/account.go +0 -180
  51. package/database/block.go +0 -362
  52. package/database/certs.go +0 -53
  53. package/database/commit_timestamp.go +0 -77
  54. package/database/database.go +0 -118
  55. package/database/database_test.go +0 -62
  56. package/database/drep.go +0 -47
  57. package/database/epoch.go +0 -121
  58. package/database/immutable/chunk.go +0 -182
  59. package/database/immutable/immutable.go +0 -350
  60. package/database/immutable/immutable_test.go +0 -59
  61. package/database/immutable/primary.go +0 -106
  62. package/database/immutable/secondary.go +0 -103
  63. package/database/immutable/testdata/08893.chunk +0 -0
  64. package/database/immutable/testdata/08893.primary +0 -0
  65. package/database/immutable/testdata/08893.secondary +0 -0
  66. package/database/immutable/testdata/08894.chunk +0 -0
  67. package/database/immutable/testdata/08894.primary +0 -0
  68. package/database/immutable/testdata/08894.secondary +0 -0
  69. package/database/immutable/testdata/README.md +0 -4
  70. package/database/plugin/blob/badger/commit_timestamp.go +0 -50
  71. package/database/plugin/blob/badger/database.go +0 -152
  72. package/database/plugin/blob/badger/logger.go +0 -63
  73. package/database/plugin/blob/badger/metrics.go +0 -98
  74. package/database/plugin/blob/blob.go +0 -19
  75. package/database/plugin/blob/store.go +0 -40
  76. package/database/plugin/log.go +0 -27
  77. package/database/plugin/metadata/metadata.go +0 -19
  78. package/database/plugin/metadata/sqlite/account.go +0 -313
  79. package/database/plugin/metadata/sqlite/certs.go +0 -58
  80. package/database/plugin/metadata/sqlite/commit_timestamp.go +0 -68
  81. package/database/plugin/metadata/sqlite/database.go +0 -218
  82. package/database/plugin/metadata/sqlite/drep.go +0 -140
  83. package/database/plugin/metadata/sqlite/epoch.go +0 -120
  84. package/database/plugin/metadata/sqlite/models/account.go +0 -118
  85. package/database/plugin/metadata/sqlite/models/auth_committee_hot.go +0 -26
  86. package/database/plugin/metadata/sqlite/models/drep.go +0 -52
  87. package/database/plugin/metadata/sqlite/models/epoch.go +0 -31
  88. package/database/plugin/metadata/sqlite/models/models.go +0 -46
  89. package/database/plugin/metadata/sqlite/models/pool.go +0 -97
  90. package/database/plugin/metadata/sqlite/models/pparam_update.go +0 -27
  91. package/database/plugin/metadata/sqlite/models/pparams.go +0 -27
  92. package/database/plugin/metadata/sqlite/models/resign_committee_cold.go +0 -27
  93. package/database/plugin/metadata/sqlite/models/stake_vote_delegation.go +0 -27
  94. package/database/plugin/metadata/sqlite/models/tip.go +0 -26
  95. package/database/plugin/metadata/sqlite/models/update_drep.go +0 -27
  96. package/database/plugin/metadata/sqlite/models/utxo.go +0 -30
  97. package/database/plugin/metadata/sqlite/models/vote_delegation.go +0 -26
  98. package/database/plugin/metadata/sqlite/models/vote_registration_delegation.go +0 -15
  99. package/database/plugin/metadata/sqlite/pool.go +0 -240
  100. package/database/plugin/metadata/sqlite/pparams.go +0 -110
  101. package/database/plugin/metadata/sqlite/tip.go +0 -83
  102. package/database/plugin/metadata/sqlite/utxo.go +0 -292
  103. package/database/plugin/metadata/store.go +0 -198
  104. package/database/plugin/option.go +0 -190
  105. package/database/plugin/plugin.go +0 -20
  106. package/database/plugin/register.go +0 -118
  107. package/database/pparams.go +0 -145
  108. package/database/tip.go +0 -45
  109. package/database/txn.go +0 -147
  110. package/database/types/types.go +0 -74
  111. package/database/types/types_test.go +0 -83
  112. package/database/utxo.go +0 -263
  113. package/dist/artifacts.json +0 -1
  114. package/dist/checksums.txt +0 -22
  115. package/dist/config.yaml +0 -253
  116. package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz +0 -0
  117. package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz.sbom.json +0 -1
  118. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz +0 -0
  119. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz.sbom.json +0 -1
  120. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz +0 -0
  121. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz.sbom.json +0 -1
  122. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk +0 -0
  123. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk.sbom.json +0 -1
  124. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb +0 -0
  125. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb.sbom.json +0 -1
  126. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm +0 -0
  127. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm.sbom.json +0 -1
  128. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk +0 -0
  129. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk.sbom.json +0 -1
  130. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb +0 -0
  131. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb.sbom.json +0 -1
  132. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm +0 -0
  133. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm.sbom.json +0 -1
  134. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz +0 -0
  135. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz.sbom.json +0 -1
  136. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz +0 -0
  137. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz.sbom.json +0 -1
  138. package/dist/dingo_darwin_amd64_v1/dingo +0 -0
  139. package/dist/dingo_darwin_arm64_v8.0/dingo +0 -0
  140. package/dist/dingo_linux_amd64_v1/dingo +0 -0
  141. package/dist/dingo_linux_arm64_v8.0/dingo +0 -0
  142. package/dist/homebrew/dingo.rb +0 -51
  143. package/dist/metadata.json +0 -1
  144. package/event/event.go +0 -141
  145. package/event/event_test.go +0 -115
  146. package/event/metrics.go +0 -44
  147. package/go.mod +0 -98
  148. package/go.sum +0 -358
  149. package/internal/config/config.go +0 -145
  150. package/internal/config/config_test.go +0 -118
  151. package/internal/node/load.go +0 -149
  152. package/internal/node/node.go +0 -176
  153. package/internal/version/version.go +0 -33
  154. package/ledger/certs.go +0 -164
  155. package/ledger/chainsync.go +0 -504
  156. package/ledger/delta.go +0 -99
  157. package/ledger/eras/allegra.go +0 -154
  158. package/ledger/eras/alonzo.go +0 -156
  159. package/ledger/eras/babbage.go +0 -154
  160. package/ledger/eras/byron.go +0 -42
  161. package/ledger/eras/conway.go +0 -166
  162. package/ledger/eras/eras.go +0 -44
  163. package/ledger/eras/mary.go +0 -154
  164. package/ledger/eras/shelley.go +0 -164
  165. package/ledger/error.go +0 -19
  166. package/ledger/event.go +0 -50
  167. package/ledger/metrics.go +0 -53
  168. package/ledger/queries.go +0 -258
  169. package/ledger/slot.go +0 -127
  170. package/ledger/slot_test.go +0 -147
  171. package/ledger/state.go +0 -821
  172. package/ledger/view.go +0 -73
  173. package/localstatequery.go +0 -50
  174. package/localtxmonitor.go +0 -44
  175. package/localtxsubmission.go +0 -52
  176. package/mempool/consumer.go +0 -98
  177. package/mempool/mempool.go +0 -322
  178. package/node.go +0 -320
  179. package/peergov/event.go +0 -27
  180. package/peergov/peer.go +0 -67
  181. package/peergov/peergov.go +0 -290
  182. package/peersharing.go +0 -70
  183. package/preview-local-topology.json +0 -23
  184. package/topology/topology.go +0 -69
  185. package/topology/topology_test.go +0 -179
  186. package/tracing.go +0 -65
  187. package/txsubmission.go +0 -233
  188. package/utxorpc/query.go +0 -311
  189. package/utxorpc/submit.go +0 -395
  190. package/utxorpc/sync.go +0 -276
  191. package/utxorpc/utxorpc.go +0 -166
  192. 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
- }