1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-28 14:56:33 -04:00

code cleanup

This commit is contained in:
Darien Raymond 2017-05-24 01:35:05 +02:00
parent ade88fd5c7
commit 62b01ef0ba
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -89,7 +89,9 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
allowedClients := vmess.NewTimedUserValidator(ctx, protocol.DefaultIDHash)
for _, user := range config.User {
allowedClients.Add(user)
if err := allowedClients.Add(user); err != nil {
return nil, newError("failed to initiate user").Base(err)
}
}
handler := &Handler{
@ -172,7 +174,8 @@ func transferResponse(timer signal.ActivityTimer, session *encoding.ServerSessio
// Process implements proxy.Inbound.Process().
func (v *Handler) Process(ctx context.Context, network net.Network, connection internet.Connection, dispatcher dispatcher.Interface) error {
connection.SetReadDeadline(time.Now().Add(time.Second * 8))
common.Must(connection.SetReadDeadline(time.Now().Add(time.Second * 8)))
reader := buf.NewBufferedReader(connection)
session := encoding.NewServerSession(v.clients, v.sessionHistory)
@ -215,12 +218,13 @@ func (v *Handler) Process(ctx context.Context, network net.Network, connection i
return transferRequest(timer, session, request, reader, input)
})
writer := buf.NewBufferedWriter(connection)
response := &protocol.ResponseHeader{
Command: v.generateCommand(ctx, request),
}
responseDone := signal.ExecuteAsync(func() error {
writer := buf.NewBufferedWriter(connection)
defer writer.Flush()
response := &protocol.ResponseHeader{
Command: v.generateCommand(ctx, request),
}
return transferResponse(timer, session, request, response, output, writer)
})
@ -230,10 +234,6 @@ func (v *Handler) Process(ctx context.Context, network net.Network, connection i
return newError("connection ends").Base(err)
}
if err := writer.Flush(); err != nil {
return newError("error during flushing remaining data").Base(err)
}
runtime.KeepAlive(timer)
return nil